Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Action/Api/BaseApiAwareAction.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Payum\Slimpay\Action\Api;

use HapiClient\Exception\HttpException;
use Payum\Core\Action\ActionInterface;
use Payum\Core\ApiAwareInterface;
use Payum\Core\ApiAwareTrait;
Expand All @@ -22,4 +23,21 @@ public function __construct()
{
$this->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();
}
}
25 changes: 15 additions & 10 deletions Action/Api/CheckoutIframeAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}
Expand Down
8 changes: 7 additions & 1 deletion Action/Api/CheckoutRedirectAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}

/**
Expand Down
11 changes: 8 additions & 3 deletions Action/Api/GetOrderPaymentReferenceAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

/**
Expand Down
25 changes: 15 additions & 10 deletions Action/Api/PaymentAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}

/**
Expand Down
25 changes: 15 additions & 10 deletions Action/Api/RefundAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

/**
Expand Down
33 changes: 19 additions & 14 deletions Action/Api/SetUpCardAliasAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down
61 changes: 33 additions & 28 deletions Action/Api/SignMandateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down
11 changes: 8 additions & 3 deletions Action/Api/SyncOrderAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}

/**
Expand Down
11 changes: 8 additions & 3 deletions Action/Api/SyncPaymentAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}

/**
Expand Down
Loading