Wrap getting token in the try-catch block

This commit is contained in:
Benjamin Beganović 2021-09-05 13:20:37 +02:00
parent 831fbade7b
commit 67f00214fa

View File

@ -134,8 +134,9 @@ class CreditCard
return $data['token']; return $data['token'];
} }
$gateway_response = json_decode($data['gateway_response']); $gateway_response = \json_decode($data['gateway_response']);
try {
$payment_method = $this->braintree->gateway->paymentMethod()->create([ $payment_method = $this->braintree->gateway->paymentMethod()->create([
'customerId' => $customerId, 'customerId' => $customerId,
'paymentMethodNonce' => $gateway_response->nonce, 'paymentMethodNonce' => $gateway_response->nonce,
@ -145,6 +146,20 @@ class CreditCard
]); ]);
return $payment_method->paymentMethod->token; return $payment_method->paymentMethod->token;
} catch(\Exception $e) {
SystemLogger::dispatch(
$e->getMessage(),
SystemLog::CATEGORY_GATEWAY_RESPONSE,
SystemLog::EVENT_GATEWAY_FAILURE,
SystemLog::TYPE_BRAINTREE,
$this->braintree->client,
$this->braintree->client->company,
);
nlog(['e' => $e->getMessage(), 'class' => \get_class($e)]);
throw new PaymentFailed($e->getMessage(), $e->getCode());
}
} }
private function processSuccessfulPayment($response) private function processSuccessfulPayment($response)