diff --git a/Action/Api/BaseApiAwareAction.php b/Action/Api/BaseApiAwareAction.php index ad843c4..22e9d8e 100644 --- a/Action/Api/BaseApiAwareAction.php +++ b/Action/Api/BaseApiAwareAction.php @@ -1,6 +1,7 @@ apiClass = Api::class; } + + /** + * @param \ArrayAccess $details + * @param HttpException $e + * @param object $request + */ + protected function populateDetailsWithError(\ArrayAccess $details, HttpException $e, $request) + { + $details['error_request'] = get_class($request); + $details['error_file'] = $e->getFile(); + $details['error_line'] = $e->getLine(); + $details['error_code'] = (int) $e->getCode(); + $details['error_message'] = $e->getMessage(); + $details['error_reason_phrase'] = $e->getReasonPhrase(); + $details['error_response_body'] = $e->getResponseBody(); + $details['error_response_code'] = $e->getStatusCode(); + } } diff --git a/Action/Api/CheckoutIframeAction.php b/Action/Api/CheckoutIframeAction.php index 6831f6d..8584e5a 100644 --- a/Action/Api/CheckoutIframeAction.php +++ b/Action/Api/CheckoutIframeAction.php @@ -2,6 +2,7 @@ namespace Payum\Slimpay\Action\Api; +use HapiClient\Exception\HttpException; use HapiClient\Hal\Resource; use Payum\Core\Bridge\Spl\ArrayObject; use Payum\Core\Exception\LogicException; @@ -37,19 +38,23 @@ public function execute($request) throw new LogicException(sprintf('Iframe is not available for mode %s', $model['checkout_mode'])); } - $iframe = $this->api->getCheckoutIframe($order, $model['checkout_mode']); + try { + $iframe = $this->api->getCheckoutIframe($order, $model['checkout_mode']); - $renderTemplate = new RenderTemplate($model['authorize_template'], array( - 'snippet' => $iframe, - )); - $this->gateway->execute($renderTemplate); + $renderTemplate = new RenderTemplate($model['authorize_template'], array( + 'snippet' => $iframe, + )); + $this->gateway->execute($renderTemplate); - $replay = new SlimpayHttpResponse($renderTemplate->getResult()); - $replay->setOrder($order); - $replay->setModel($model['authorize_template']); - $replay->setSnippet($iframe); + $replay = new SlimpayHttpResponse($renderTemplate->getResult()); + $replay->setOrder($order); + $replay->setModel($model['authorize_template']); + $replay->setSnippet($iframe); - throw $replay; + throw $replay; + } catch (HttpException $e) { + $this->populateDetailsWithError($model, $e, $request); + } } /** * {@inheritDoc} diff --git a/Action/Api/CheckoutRedirectAction.php b/Action/Api/CheckoutRedirectAction.php index 19337f0..2371671 100644 --- a/Action/Api/CheckoutRedirectAction.php +++ b/Action/Api/CheckoutRedirectAction.php @@ -2,6 +2,7 @@ namespace Payum\Slimpay\Action\Api; +use HapiClient\Exception\HttpException; use HapiClient\Hal\Resource; use Payum\Core\Bridge\Spl\ArrayObject; use Payum\Core\Exception\LogicException; @@ -28,11 +29,16 @@ public function execute($request) if (! $order instanceof Resource) { throw new LogicException('Order should be an instance of Resource'); } + if (Constants::CHECKOUT_MODE_REDIRECT != $model['checkout_mode']) { throw new LogicException(sprintf('Redirect is not available for mode %s', $model['checkout_mode'])); } - throw new HttpRedirect($this->api->getCheckoutRedirect($order)); + try { + throw new HttpRedirect($this->api->getCheckoutRedirect($order)); + } catch (HttpException $e) { + $this->populateDetailsWithError($model, $e, $request); + } } /** diff --git a/Action/Api/GetOrderPaymentReferenceAction.php b/Action/Api/GetOrderPaymentReferenceAction.php index 4dc8735..2a0d6fe 100644 --- a/Action/Api/GetOrderPaymentReferenceAction.php +++ b/Action/Api/GetOrderPaymentReferenceAction.php @@ -3,6 +3,7 @@ namespace Payum\Slimpay\Action\Api; +use HapiClient\Exception\HttpException; use Payum\Core\Bridge\Spl\ArrayObject; use Payum\Core\Exception\LogicException; use Payum\Core\Exception\RequestNotSupportedException; @@ -37,9 +38,13 @@ public function execute($request) $follow = Constants::FOLLOW_GET_MANDATE; } - $model['reference'] = ResourceSerializer::serializeResource( - $this->api->getOrderPaymentReference($order, $follow) - ); + try { + $model['reference'] = ResourceSerializer::serializeResource( + $this->api->getOrderPaymentReference($order, $follow) + ); + } catch (HttpException $e) { + $this->populateDetailsWithError($model, $e, $request); + } } /** diff --git a/Action/Api/PaymentAction.php b/Action/Api/PaymentAction.php index c63705e..5ab6e38 100644 --- a/Action/Api/PaymentAction.php +++ b/Action/Api/PaymentAction.php @@ -3,6 +3,7 @@ namespace Payum\Slimpay\Action\Api; +use HapiClient\Exception\HttpException; use Payum\Core\Bridge\Spl\ArrayObject; use Payum\Core\Exception\RequestNotSupportedException; use Payum\Slimpay\Request\Api\Payment; @@ -23,16 +24,20 @@ public function execute($request) $model->validateNotEmpty(['amount', 'currency', 'payment_scheme', 'payment_reference']); - $model['payment'] = ResourceSerializer::serializeResource( - $this->api->createPayment($model['payment_scheme'], $model['payment_reference'], [ - 'reference' => $model['reference'], - 'amount' => $model['amount'], - 'currency' => $model['currency'], - 'scheme' => $model['payment_scheme'], - 'label' => $model['label'], - 'executionDate' => $model['execution_date'] - ]) - ); + try { + $model['payment'] = ResourceSerializer::serializeResource( + $this->api->createPayment($model['payment_scheme'], $model['payment_reference'], [ + 'reference' => $model['reference'], + 'amount' => $model['amount'], + 'currency' => $model['currency'], + 'scheme' => $model['payment_scheme'], + 'label' => $model['label'], + 'executionDate' => $model['execution_date'] + ]) + ); + } catch (HttpException $e) { + $this->populateDetailsWithError($model, $e, $request); + } } /** diff --git a/Action/Api/RefundAction.php b/Action/Api/RefundAction.php index 3f10fe2..4bf8662 100644 --- a/Action/Api/RefundAction.php +++ b/Action/Api/RefundAction.php @@ -2,6 +2,7 @@ namespace Payum\Slimpay\Action\Api; +use HapiClient\Exception\HttpException; use Payum\Core\Bridge\Spl\ArrayObject; use Payum\Core\Exception\LogicException; use Payum\Core\Exception\RequestNotSupportedException; @@ -32,16 +33,20 @@ public function execute($request) )); } - $model['payment'] = ResourceSerializer::serializeResource( - $this->api->refundPayment($model['payment_scheme'], $model['mandate_reference'], [ - 'reference' => $model['reference'], - 'amount' => $model['amount'], - 'currency' => $model['currency'], - 'scheme' => $model['payment_scheme'], - 'label' => $model['label'], - 'executionDate' => $model['execution_date'] - ]) - ); + try { + $model['payment'] = ResourceSerializer::serializeResource( + $this->api->refundPayment($model['payment_scheme'], $model['mandate_reference'], [ + 'reference' => $model['reference'], + 'amount' => $model['amount'], + 'currency' => $model['currency'], + 'scheme' => $model['payment_scheme'], + 'label' => $model['label'], + 'executionDate' => $model['execution_date'] + ]) + ); + } catch (HttpException $e) { + $this->populateDetailsWithError($model, $e, $request); + } } /** diff --git a/Action/Api/SetUpCardAliasAction.php b/Action/Api/SetUpCardAliasAction.php index a549c0d..e9cb5b3 100644 --- a/Action/Api/SetUpCardAliasAction.php +++ b/Action/Api/SetUpCardAliasAction.php @@ -3,6 +3,7 @@ namespace Payum\Slimpay\Action\Api; +use HapiClient\Exception\HttpException; use Payum\Core\Bridge\Spl\ArrayObject; use Payum\Core\Exception\LogicException; use Payum\Core\Exception\RequestNotSupportedException; @@ -35,23 +36,27 @@ public function execute($request) $model->validateNotEmpty(['subscriber_reference']); - $model['order'] = ResourceSerializer::serializeResource( - $this->api->setUpCardAlias($model['subscriber_reference']) - ); + try { + $model['order'] = ResourceSerializer::serializeResource( + $this->api->setUpCardAlias($model['subscriber_reference']) + ); - if(null === $model['checkout_mode']) { - $model['checkout_mode'] = $this->api->getDefaultCheckoutMode(); - } + if(null === $model['checkout_mode']) { + $model['checkout_mode'] = $this->api->getDefaultCheckoutMode(); + } - $model->validateNotEmpty(['checkout_mode']); + $model->validateNotEmpty(['checkout_mode']); - if(Constants::CHECKOUT_MODE_REDIRECT == $model['checkout_mode']) { - $this->gateway->execute(new CheckoutRedirect($model)); - } elseif (in_array( - $model['checkout_mode'], - [Constants::CHECKOUT_MODE_IFRAME_EMBADDED, Constants::CHECKOUT_MODE_IFRAME_POPIN] - )) { - $this->gateway->execute(new CheckoutIframe($model)); + if(Constants::CHECKOUT_MODE_REDIRECT == $model['checkout_mode']) { + $this->gateway->execute(new CheckoutRedirect($model)); + } elseif (in_array( + $model['checkout_mode'], + [Constants::CHECKOUT_MODE_IFRAME_EMBADDED, Constants::CHECKOUT_MODE_IFRAME_POPIN] + )) { + $this->gateway->execute(new CheckoutIframe($model)); + } + } catch (HttpException $e) { + $this->populateDetailsWithError($model, $e, $request); } } diff --git a/Action/Api/SignMandateAction.php b/Action/Api/SignMandateAction.php index f8d3cd3..be8eb6a 100644 --- a/Action/Api/SignMandateAction.php +++ b/Action/Api/SignMandateAction.php @@ -2,6 +2,7 @@ namespace Payum\Slimpay\Action\Api; +use HapiClient\Exception\HttpException; use Payum\Core\Bridge\Spl\ArrayObject; use Payum\Core\Exception\LogicException; use Payum\Core\Exception\RequestNotSupportedException; @@ -42,37 +43,41 @@ public function execute($request) 'country' ]); - if(null === $model['checkout_mode']) { - $model['checkout_mode'] = $this->api->getDefaultCheckoutMode(); - } + try { + if(null === $model['checkout_mode']) { + $model['checkout_mode'] = $this->api->getDefaultCheckoutMode(); + } - $model->validateNotEmpty(['checkout_mode']); + $model->validateNotEmpty(['checkout_mode']); - $model['order'] = ResourceSerializer::serializeResource( - $this->api->signMandate($model['subscriber_reference'], $model['payment_scheme'], [ - 'givenName' => $model['first_name'], - 'familyName' => $model['last_name'], - 'email' => $model['email'], - 'telephone' => $model['phone'], - 'companyName' => $model['company'], - 'organizationName' => $model['organization'], - 'billingAddress' => [ - 'street1' => $model['address1'], - 'street2' => $model['address2'], - 'city' => $model['city'], - 'postalCode' => $model['zip'], - 'country' => $model['country'] - ] - ]) - ); + $model['order'] = ResourceSerializer::serializeResource( + $this->api->signMandate($model['subscriber_reference'], $model['payment_scheme'], [ + 'givenName' => $model['first_name'], + 'familyName' => $model['last_name'], + 'email' => $model['email'], + 'telephone' => $model['phone'], + 'companyName' => $model['company'], + 'organizationName' => $model['organization'], + 'billingAddress' => [ + 'street1' => $model['address1'], + 'street2' => $model['address2'], + 'city' => $model['city'], + 'postalCode' => $model['zip'], + 'country' => $model['country'] + ] + ]) + ); - if(Constants::CHECKOUT_MODE_REDIRECT == $model['checkout_mode']) { - $this->gateway->execute(new CheckoutRedirect($model)); - } elseif (in_array( - $model['checkout_mode'], - [Constants::CHECKOUT_MODE_IFRAME_EMBADDED, Constants::CHECKOUT_MODE_IFRAME_POPIN] - )) { - $this->gateway->execute(new CheckoutIframe($model)); + if(Constants::CHECKOUT_MODE_REDIRECT == $model['checkout_mode']) { + $this->gateway->execute(new CheckoutRedirect($model)); + } elseif (in_array( + $model['checkout_mode'], + [Constants::CHECKOUT_MODE_IFRAME_EMBADDED, Constants::CHECKOUT_MODE_IFRAME_POPIN] + )) { + $this->gateway->execute(new CheckoutIframe($model)); + } + } catch (HttpException $e) { + $this->populateDetailsWithError($model, $e, $request); } } diff --git a/Action/Api/SyncOrderAction.php b/Action/Api/SyncOrderAction.php index 732648f..a6d073f 100644 --- a/Action/Api/SyncOrderAction.php +++ b/Action/Api/SyncOrderAction.php @@ -2,6 +2,7 @@ namespace Payum\Slimpay\Action\Api; +use HapiClient\Exception\HttpException; use Payum\Core\Bridge\Spl\ArrayObject; use Payum\Core\Exception\RequestNotSupportedException; use Payum\Slimpay\Request\Api\SyncOrder; @@ -24,9 +25,13 @@ public function execute($request) $order = ResourceSerializer::unserializeResource($model['order']); - $model['order'] = ResourceSerializer::serializeResource( - $this->api->getOrder($order->getState()['id']) - ); + try { + $model['order'] = ResourceSerializer::serializeResource( + $this->api->getOrder($order->getState()['id']) + ); + } catch (HttpException $e) { + $this->populateDetailsWithError($model, $e, $request); + } } /** diff --git a/Action/Api/SyncPaymentAction.php b/Action/Api/SyncPaymentAction.php index e6312f1..9996220 100644 --- a/Action/Api/SyncPaymentAction.php +++ b/Action/Api/SyncPaymentAction.php @@ -2,6 +2,7 @@ namespace Payum\Slimpay\Action\Api; +use HapiClient\Exception\HttpException; use Payum\Core\Bridge\Spl\ArrayObject; use Payum\Core\Exception\RequestNotSupportedException; use Payum\Slimpay\Request\Api\SyncPayment; @@ -24,9 +25,13 @@ public function execute($request) $payment = ResourceSerializer::unserializeResource($model['payment']); - $model['payment'] = ResourceSerializer::serializeResource( - $this->api->getPayment($payment->getState()['id']) - ); + try { + $model['payment'] = ResourceSerializer::serializeResource( + $this->api->getPayment($payment->getState()['id']) + ); + } catch (HttpException $e) { + $this->populateDetailsWithError($model, $e, $request); + } } /** diff --git a/Action/Api/UpdatePaymentMethodWithCheckoutAction.php b/Action/Api/UpdatePaymentMethodWithCheckoutAction.php index 2ca9d92..2e80fcf 100644 --- a/Action/Api/UpdatePaymentMethodWithCheckoutAction.php +++ b/Action/Api/UpdatePaymentMethodWithCheckoutAction.php @@ -3,6 +3,7 @@ namespace Payum\Slimpay\Action\Api; +use HapiClient\Exception\HttpException; use Payum\Core\Bridge\Spl\ArrayObject; use Payum\Core\Exception\RequestNotSupportedException; use Payum\Slimpay\Constants; @@ -26,24 +27,28 @@ public function execute($request) $model->validateNotEmpty(['subscriber_reference', 'mandate_reference']); - $model['order'] = ResourceSerializer::serializeResource($this->api->updatePaymentMethodWithCheckout( - $model['subscriber_reference'], - $model['mandate_reference'] - )); - - if(null === $model['checkout_mode']) { - $model['checkout_mode'] = $this->api->getDefaultCheckoutMode(); - } - - $model->validateNotEmpty(['checkout_mode']); - - if(Constants::CHECKOUT_MODE_REDIRECT == $model['checkout_mode']) { - $this->gateway->execute(new CheckoutRedirect($model)); - } elseif (in_array( - $model['checkout_mode'], - [Constants::CHECKOUT_MODE_IFRAME_EMBADDED, Constants::CHECKOUT_MODE_IFRAME_POPIN] - )) { - $this->gateway->execute(new CheckoutIframe($model)); + try { + $model['order'] = ResourceSerializer::serializeResource($this->api->updatePaymentMethodWithCheckout( + $model['subscriber_reference'], + $model['mandate_reference'] + )); + + if(null === $model['checkout_mode']) { + $model['checkout_mode'] = $this->api->getDefaultCheckoutMode(); + } + + $model->validateNotEmpty(['checkout_mode']); + + if(Constants::CHECKOUT_MODE_REDIRECT == $model['checkout_mode']) { + $this->gateway->execute(new CheckoutRedirect($model)); + } elseif (in_array( + $model['checkout_mode'], + [Constants::CHECKOUT_MODE_IFRAME_EMBADDED, Constants::CHECKOUT_MODE_IFRAME_POPIN] + )) { + $this->gateway->execute(new CheckoutIframe($model)); + } + } catch (HttpException $e) { + $this->populateDetailsWithError($model, $e, $request); } } diff --git a/Action/Api/UpdatePaymentMethodWithIbanAction.php b/Action/Api/UpdatePaymentMethodWithIbanAction.php index 75ace10..1a5e2e8 100644 --- a/Action/Api/UpdatePaymentMethodWithIbanAction.php +++ b/Action/Api/UpdatePaymentMethodWithIbanAction.php @@ -2,6 +2,7 @@ namespace Payum\Slimpay\Action\Api; +use HapiClient\Exception\HttpException; use Payum\Core\Bridge\Spl\ArrayObject; use Payum\Core\Exception\RequestNotSupportedException; use Payum\Slimpay\Request\Api\UpdatePaymentMethodWithIban; @@ -22,9 +23,13 @@ public function execute($request) $model->validateNotEmpty(['iban', 'mandate_reference']); - $model['bank_account'] = ResourceSerializer::serializeResource( - $this->api->updatePaymentMethodWithIban($model['mandate_reference'], $model['iban']) - ); + try { + $model['bank_account'] = ResourceSerializer::serializeResource( + $this->api->updatePaymentMethodWithIban($model['mandate_reference'], $model['iban']) + ); + } catch (HttpException $e) { + $this->populateDetailsWithError($model, $e, $request); + } } /**