This repository has been archived by the owner on Mar 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from heidelpay/feature/PLENTY-88/add-sync-request
feature/PLENTY-88/add-sync-request
- Loading branch information
Showing
11 changed files
with
376 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
/** | ||
* Performs credit card transaction requests. | ||
* | ||
* @license Use of this software requires acceptance of the License Agreement. See LICENSE file. | ||
* @copyright Copyright © 2017-present heidelpay GmbH. All rights reserved. | ||
* | ||
* @link https://dev.heidelpay.com/plentymarkets | ||
* | ||
* @author Simon Gabriel <[email protected]> | ||
* | ||
* @package heidelpay\plentymarkets-gateway\external-lib-callbacks | ||
*/ | ||
|
||
use Heidelpay\PhpPaymentApi\Request; | ||
|
||
/** @var array $requestParams */ | ||
$requestParams = SdkRestApi::getParam('request'); | ||
$transactionType = SdkRestApi::getParam('transactionType'); | ||
|
||
$paymentMethod = new \Heidelpay\PhpPaymentApi\PaymentMethods\InvoiceB2CSecuredPaymentMethod(); | ||
$paymentMethod->setRequest(Request::fromPost($requestParams)); | ||
|
||
$responseArray = null; | ||
|
||
$refId = SdkRestApi::getParam('referenceId') ?: null; | ||
$paymentFrameOrigin = $paymentMethod->getRequest()->getFrontend()->getPaymentFrameOrigin(); | ||
$preventAsyncRedirect = $paymentMethod->getRequest()->getFrontend()->getPreventAsyncRedirect(); | ||
$cssPath = $paymentMethod->getRequest()->getFrontend()->getCssPath(); | ||
|
||
try { | ||
if (!is_callable([$paymentMethod, $transactionType])) { | ||
throw new \Exception('Invalid transaction type for InvoiceB2CSecured payment method (' . $transactionType . ')!'); | ||
} | ||
|
||
if ($refId !== null) { | ||
$response = $paymentMethod->{$transactionType}( | ||
$refId, | ||
$paymentFrameOrigin, | ||
$preventAsyncRedirect, | ||
$cssPath | ||
); | ||
} else { | ||
$response = $paymentMethod->{$transactionType}($paymentFrameOrigin, $preventAsyncRedirect, $cssPath); | ||
} | ||
} catch (\Exception $e) { | ||
$errorResponse = [ | ||
'exceptionCode' => $e->getCode(), | ||
'exceptionMsg' => $e->getMessage(), | ||
'exceptionTrace' => $e->getTraceAsString(), | ||
]; | ||
} | ||
|
||
// return the responseArray, if an exception has been thrown. | ||
// else, return an array containing response results. | ||
$responseObj = $paymentMethod->getResponse(); | ||
$responseArray = $responseObj->toArray(); | ||
ksort($responseArray); | ||
return $errorResponse ?? [ | ||
'response' => $responseArray, | ||
'isSuccess' => $responseObj->isSuccess(), | ||
'isPending' => $responseObj->isPending(), | ||
'isError' => $responseObj->isError(), | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.