diff --git a/samples/Exchange.php b/samples/Exchange.php index 71d6031..5c87214 100644 --- a/samples/Exchange.php +++ b/samples/Exchange.php @@ -7,7 +7,6 @@ require '../../../../vendor/autoload.php'; use PayNL\Sdk\Util\Exchange; -use PayNL\Sdk\Model\Pay\PayStatus; $exchange = new Exchange(); @@ -15,18 +14,29 @@ # Process the exchange request $payOrder = $exchange->process(); - switch ($payOrder->getStateId()) { - case PayStatus::PENDING : - $responseResult = yourCodeToProcessPendingOrder($payOrder->getReference()); - $responseMessage = 'Processed pending'; - break; - case PayStatus::PAID : - $responseResult = yourCodeToProcessPaidOrder($payOrder->getReference()); - $responseMessage = 'Processed paid. Order: ' . $payOrder->getReference(); - break; - default : - $responseResult = true; - $responseMessage = 'No action defined for payment state ' . $payOrder->getStateId(); + if($payOrder->isPending()) { + $responseResult = yourCodeToProcessPendingOrder($payOrder->getReference()); + $responseMessage = 'Processed pending'; + + } + elseif($payOrder->isPaid() || $payOrder->isAuthorized()) { + $responseResult = yourCodeToProcessPaidOrder($payOrder->getReference()); + $responseMessage = 'Processed paid. Order: ' . $payOrder->getReference(); + + } + elseif($payOrder->isRefunded()) { + $responseResult = true; # Your code to process refund here + $responseMessage = 'Processed refund.'; + + } + elseif($payOrder->isCancelled()) { + $responseResult = true; # Your code to cancel order here + $responseMessage = 'Processed cancelled.'; + + } + else { + $responseResult = true; + $responseMessage = 'No action defined for payment state '. $payOrder->getStatusCode(); } } catch (Throwable $exception) { $responseResult = false; diff --git a/samples/OrderAbort.php b/samples/OrderAbort.php index 8aec20e..0d66147 100644 --- a/samples/OrderAbort.php +++ b/samples/OrderAbort.php @@ -37,8 +37,8 @@ echo 'getTransactionId: ' . $transaction->getOrderId() . PHP_EOL; echo 'getDescription: ' . $transaction->getDescription() . PHP_EOL; echo 'getReference: ' . $transaction->getReference() . PHP_EOL; -echo 'getAmount getValue: ' . $transaction->getAmount()->getValue() . PHP_EOL; -echo 'getAmount getCurrency: ' . $transaction->getAmount()->getCurrency() . PHP_EOL; +echo 'getAmount getValue: ' . $transaction->getAmount() . PHP_EOL; +echo 'getAmount getCurrency: ' . $transaction->getAmount() . PHP_EOL; echo 'getAuthorizedAmount getCurrency: ' . $transaction->getAuthorizedAmount()->getCurrency() . PHP_EOL; echo 'getAuthorizedAmount getValue: ' . $transaction->getAuthorizedAmount()->getValue() . PHP_EOL; echo 'getStatus:' . print_r($transaction->getStatus(), true) . PHP_EOL; diff --git a/samples/OrderApprove.php b/samples/OrderApprove.php index 8abd72c..c921097 100644 --- a/samples/OrderApprove.php +++ b/samples/OrderApprove.php @@ -20,7 +20,7 @@ $orderApproveRequest->setConfig($config); try { - $transaction = $orderApproveRequest->start(); + $payOrder = $orderApproveRequest->start(); } catch (PayException $e) { echo '
'; echo 'Technical message: ' . $e->getMessage() . PHP_EOL; @@ -33,20 +33,17 @@ echo ''; echo 'Success, values:' . PHP_EOL; -echo 'getOrderId: ' . $transaction->getId() . PHP_EOL; -echo 'getTransactionId: ' . $transaction->getOrderId() . PHP_EOL; -echo 'getDescription: ' . $transaction->getDescription() . PHP_EOL; -echo 'getReference: ' . $transaction->getReference() . PHP_EOL; -echo 'getAmount getValue: ' . $transaction->getAmount()->getValue() . PHP_EOL; -echo 'getAmount getCurrency: ' . $transaction->getAmount()->getCurrency() . PHP_EOL; -echo 'getAuthorizedAmount getCurrency: ' . $transaction->getAuthorizedAmount()->getCurrency() . PHP_EOL; -echo 'getAuthorizedAmount getValue: ' . $transaction->getAuthorizedAmount()->getValue() . PHP_EOL; -echo 'getStatus:' . print_r($transaction->getStatus(), true) . PHP_EOL; -echo 'getPaymentData:' . print_r($transaction->getPayments(), true) . PHP_EOL; -echo 'getIntegration:' . print_r($transaction->getIntegration(), true) . PHP_EOL; -echo 'getExpiresAt: ' . $transaction->getExpiresAt() . PHP_EOL; -echo 'getCreatedAt: ' . $transaction->getCreatedAt() . PHP_EOL; -echo 'getCreatedBy: ' . $transaction->getCreatedBy() . PHP_EOL; -echo 'getModifiedAt: ' . $transaction->getModifiedAt() . PHP_EOL; -echo 'getModifiedBy: ' . $transaction->getModifiedBy() . PHP_EOL; - +echo 'getOrderId: ' . $payOrder->getId() . PHP_EOL; +echo 'getTransactionId: ' . $payOrder->getOrderId() . PHP_EOL; +echo 'getServiceId: ' . $payOrder->getServiceId() . PHP_EOL; +echo 'getDescription: ' . $payOrder->getDescription() . PHP_EOL; +echo 'getReference: ' . $payOrder->getReference() . PHP_EOL; +echo 'getAmount getValue: ' . $payOrder->getAmount() . PHP_EOL; +echo 'getAmount getCurrency: ' . $payOrder->getCurrency() . PHP_EOL; +echo 'getStatus:' . print_r($payOrder->getStatus(), true) . PHP_EOL; +echo 'getTestmode: ' . ($payOrder->isTestmode() === true ? 'test order' : 'live order') . PHP_EOL; +echo 'getExpiresAt: ' . $payOrder->getExpiresAt() . PHP_EOL; +echo 'getCreatedAt: ' . $payOrder->getCreatedAt() . PHP_EOL; +echo 'getCreatedBy: ' . $payOrder->getCreatedBy() . PHP_EOL; +echo 'getModifiedAt: ' . $payOrder->getModifiedAt() . PHP_EOL; +echo 'getModifiedBy: ' . $payOrder->getModifiedBy() . PHP_EOL; diff --git a/samples/OrderCapture.php b/samples/OrderCapture.php index bef1dc8..7197a25 100644 --- a/samples/OrderCapture.php +++ b/samples/OrderCapture.php @@ -21,7 +21,7 @@ $orderCaptureRequest->setConfig($config); try { - $capture = $orderCaptureRequest->start(); + $payOrder = $orderCaptureRequest->start(); } catch (PayException $e) { echo ''; echo 'Technical message: ' . $e->getMessage() . PHP_EOL; @@ -33,21 +33,17 @@ echo ''; echo 'Success, values:' . PHP_EOL; -echo 'getOrderId: ' . $capture->getId() . PHP_EOL; -echo 'getTransactionId: ' . $capture->getOrderId() . PHP_EOL; -echo 'getServiceCode: ' . $capture->getServiceCode() . PHP_EOL; -echo 'getDescription: ' . $capture->getDescription() . PHP_EOL; -echo 'getReference: ' . $capture->getReference() . PHP_EOL; -echo 'getIpAddress: ' . $capture->getIpAddress() . PHP_EOL; -echo 'getAmount getValue: ' . $capture->getAmount()->getValue() . PHP_EOL; -echo 'getAmount getCurrency: ' . $capture->getAmount()->getCurrency() . PHP_EOL; -echo 'getStatus:' . print_r($capture->getStatus(), true) . PHP_EOL; - -echo 'getIntegration:' . print_r($capture->getIntegration(), true) . PHP_EOL; -echo 'getExpiresAt: ' . $capture->getExpiresAt() . PHP_EOL; -echo 'getCreatedAt: ' . $capture->getCreatedAt() . PHP_EOL; -echo 'getCreatedBy: ' . $capture->getCreatedBy() . PHP_EOL; -echo 'getModifiedAt: ' . $capture->getModifiedAt() . PHP_EOL; -echo 'getModifiedBy: ' . $capture->getModifiedBy() . PHP_EOL; -echo 'getDeletedAt: ' . $capture->getDeletedAt() . PHP_EOL; -echo 'getDeletedBy: ' . $capture->getDeletedBy() . PHP_EOL; \ No newline at end of file +echo 'getOrderId: ' . $payOrder->getId() . PHP_EOL; +echo 'getTransactionId: ' . $payOrder->getOrderId() . PHP_EOL; +echo 'getServiceId: ' . $payOrder->getServiceId() . PHP_EOL; +echo 'getDescription: ' . $payOrder->getDescription() . PHP_EOL; +echo 'getReference: ' . $payOrder->getReference() . PHP_EOL; +echo 'getAmount getValue: ' . $payOrder->getAmount() . PHP_EOL; +echo 'getAmount getCurrency: ' . $payOrder->getCurrency() . PHP_EOL; +echo 'getStatus:' . print_r($payOrder->getStatus(), true) . PHP_EOL; +echo 'getTestmode: ' . ($payOrder->isTestmode() === true ? 'test order' : 'live order') . PHP_EOL; +echo 'getExpiresAt: ' . $payOrder->getExpiresAt() . PHP_EOL; +echo 'getCreatedAt: ' . $payOrder->getCreatedAt() . PHP_EOL; +echo 'getCreatedBy: ' . $payOrder->getCreatedBy() . PHP_EOL; +echo 'getModifiedAt: ' . $payOrder->getModifiedAt() . PHP_EOL; +echo 'getModifiedBy: ' . $payOrder->getModifiedBy() . PHP_EOL; diff --git a/samples/OrderCaptureAmount.php b/samples/OrderCaptureAmount.php index 8c5b723..945c665 100644 --- a/samples/OrderCaptureAmount.php +++ b/samples/OrderCaptureAmount.php @@ -23,7 +23,7 @@ $orderCaptureRequest->setConfig($config); try { - $capture = $orderCaptureRequest->start(); + $payOrder = $orderCaptureRequest->start(); } catch (PayException $e) { echo ''; echo 'Technical message: ' . $e->getMessage() . PHP_EOL; @@ -35,21 +35,17 @@ echo ''; echo 'Success, values:' . PHP_EOL; -echo 'getOrderId: ' . $capture->getId() . PHP_EOL; -echo 'getTransactionId: ' . $capture->getOrderId() . PHP_EOL; -echo 'getServiceCode: ' . $capture->getServiceCode() . PHP_EOL; -echo 'getDescription: ' . $capture->getDescription() . PHP_EOL; -echo 'getReference: ' . $capture->getReference() . PHP_EOL; -echo 'getIpAddress: ' . $capture->getIpAddress() . PHP_EOL; -echo 'getAmount getValue: ' . $capture->getAmount()->getValue() . PHP_EOL; -echo 'getAmount getCurrency: ' . $capture->getAmount()->getCurrency() . PHP_EOL; -echo 'getStatus:' . print_r($capture->getStatus(), true) . PHP_EOL; - -echo 'getIntegration:' . print_r($capture->getIntegration(), true) . PHP_EOL; -echo 'getExpiresAt: ' . $capture->getExpiresAt() . PHP_EOL; -echo 'getCreatedAt: ' . $capture->getCreatedAt() . PHP_EOL; -echo 'getCreatedBy: ' . $capture->getCreatedBy() . PHP_EOL; -echo 'getModifiedAt: ' . $capture->getModifiedAt() . PHP_EOL; -echo 'getModifiedBy: ' . $capture->getModifiedBy() . PHP_EOL; -echo 'getDeletedAt: ' . $capture->getDeletedAt() . PHP_EOL; -echo 'getDeletedBy: ' . $capture->getDeletedBy() . PHP_EOL; \ No newline at end of file +echo 'getOrderId: ' . $payOrder->getId() . PHP_EOL; +echo 'getTransactionId: ' . $payOrder->getOrderId() . PHP_EOL; +echo 'getServiceId: ' . $payOrder->getServiceId() . PHP_EOL; +echo 'getDescription: ' . $payOrder->getDescription() . PHP_EOL; +echo 'getReference: ' . $payOrder->getReference() . PHP_EOL; +echo 'getAmount getValue: ' . $payOrder->getAmount() . PHP_EOL; +echo 'getAmount getCurrency: ' . $payOrder->getCurrency() . PHP_EOL; +echo 'getStatus:' . print_r($payOrder->getStatus(), true) . PHP_EOL; +echo 'getTestmode: ' . ($payOrder->isTestmode() === true ? 'test order' : 'live order') . PHP_EOL; +echo 'getExpiresAt: ' . $payOrder->getExpiresAt() . PHP_EOL; +echo 'getCreatedAt: ' . $payOrder->getCreatedAt() . PHP_EOL; +echo 'getCreatedBy: ' . $payOrder->getCreatedBy() . PHP_EOL; +echo 'getModifiedAt: ' . $payOrder->getModifiedAt() . PHP_EOL; +echo 'getModifiedBy: ' . $payOrder->getModifiedBy() . PHP_EOL; diff --git a/samples/OrderCaptureProduct.php b/samples/OrderCaptureProduct.php index f203e47..510f96d 100644 --- a/samples/OrderCaptureProduct.php +++ b/samples/OrderCaptureProduct.php @@ -25,7 +25,7 @@ $orderCaptureRequest->setConfig($config); try { - $capture = $orderCaptureRequest->start(); + $payOrder = $orderCaptureRequest->start(); } catch (PayException $e) { echo ''; echo 'Technical message: ' . $e->getMessage() . PHP_EOL; @@ -35,23 +35,20 @@ exit(); } + echo ''; echo 'Success, values:' . PHP_EOL; -echo 'getOrderId: ' . $capture->getId() . PHP_EOL; -echo 'getTransactionId: ' . $capture->getOrderId() . PHP_EOL; -echo 'getServiceCode: ' . $capture->getServiceCode() . PHP_EOL; -echo 'getDescription: ' . $capture->getDescription() . PHP_EOL; -echo 'getReference: ' . $capture->getReference() . PHP_EOL; -echo 'getIpAddress: ' . $capture->getIpAddress() . PHP_EOL; -echo 'getAmount getValue: ' . $capture->getAmount()->getValue() . PHP_EOL; -echo 'getAmount getCurrency: ' . $capture->getAmount()->getCurrency() . PHP_EOL; -echo 'getStatus:' . print_r($capture->getStatus(), true) . PHP_EOL; - -echo 'getIntegration:' . print_r($capture->getIntegration(), true) . PHP_EOL; -echo 'getExpiresAt: ' . $capture->getExpiresAt() . PHP_EOL; -echo 'getCreatedAt: ' . $capture->getCreatedAt() . PHP_EOL; -echo 'getCreatedBy: ' . $capture->getCreatedBy() . PHP_EOL; -echo 'getModifiedAt: ' . $capture->getModifiedAt() . PHP_EOL; -echo 'getModifiedBy: ' . $capture->getModifiedBy() . PHP_EOL; -echo 'getDeletedAt: ' . $capture->getDeletedAt() . PHP_EOL; -echo 'getDeletedBy: ' . $capture->getDeletedBy() . PHP_EOL; \ No newline at end of file +echo 'getOrderId: ' . $payOrder->getId() . PHP_EOL; +echo 'getTransactionId: ' . $payOrder->getOrderId() . PHP_EOL; +echo 'getServiceId: ' . $payOrder->getServiceId() . PHP_EOL; +echo 'getDescription: ' . $payOrder->getDescription() . PHP_EOL; +echo 'getReference: ' . $payOrder->getReference() . PHP_EOL; +echo 'getAmount getValue: ' . $payOrder->getAmount() . PHP_EOL; +echo 'getAmount getCurrency: ' . $payOrder->getCurrency() . PHP_EOL; +echo 'getStatus:' . print_r($payOrder->getStatus(), true) . PHP_EOL; +echo 'getTestmode: ' . ($payOrder->isTestmode() === true ? 'test order' : 'live order') . PHP_EOL; +echo 'getExpiresAt: ' . $payOrder->getExpiresAt() . PHP_EOL; +echo 'getCreatedAt: ' . $payOrder->getCreatedAt() . PHP_EOL; +echo 'getCreatedBy: ' . $payOrder->getCreatedBy() . PHP_EOL; +echo 'getModifiedAt: ' . $payOrder->getModifiedAt() . PHP_EOL; +echo 'getModifiedBy: ' . $payOrder->getModifiedBy() . PHP_EOL; diff --git a/samples/OrderCreate.php b/samples/OrderCreate.php index 025df40..065db05 100644 --- a/samples/OrderCreate.php +++ b/samples/OrderCreate.php @@ -108,7 +108,8 @@ $request->setConfig($config); try { - $transaction = $request->start(); + $payOrder = $request->start(); + echo get_class($payOrder); } catch (PayException $e) { echo ''; echo 'Technical message: ' . $e->getMessage() . PHP_EOL; @@ -120,20 +121,20 @@ echo ''; echo 'Success, values:' . PHP_EOL; -echo 'getId: ' . $transaction->getId() . PHP_EOL; -echo 'getServiceId: ' . $transaction->getServiceId() . PHP_EOL; -echo 'getDescription: ' . $transaction->getDescription() . PHP_EOL; -echo 'getReference: ' . $transaction->getReference() . PHP_EOL; -echo 'getManualTransferCode: ' . $transaction->getManualTransferCode() . PHP_EOL; -echo 'getOrderId: ' . $transaction->getOrderId() . PHP_EOL; -echo 'getPaymentUrl: ' . '' . $transaction->getPaymentUrl() . '' . PHP_EOL; -echo 'getStatusUrl: ' . $transaction->getStatusUrl() . PHP_EOL; -echo 'getAmount value: ' . $transaction->getAmount()->getValue() . PHP_EOL; -echo 'getAmount currency: ' . $transaction->getAmount()->getCurrency() . PHP_EOL; -echo 'getUuid: ' . $transaction->getUuid() . PHP_EOL; -echo 'expiresAt: ' . $transaction->getExpiresAt() . PHP_EOL; -echo 'createdAt: ' . $transaction->getCreatedAt() . PHP_EOL; -echo 'createdBy: ' . $transaction->getCreatedBy() . PHP_EOL; -echo 'getCreatedAt: ' . $transaction->getCreatedAt() . PHP_EOL; -echo 'modifiedAt: ' . $transaction->getModifiedAt() . PHP_EOL; -echo 'modifiedBy: ' . $transaction->getModifiedBy() . PHP_EOL; +echo 'getId: ' . $payOrder->getId() . PHP_EOL; +echo 'getServiceId: ' . $payOrder->getServiceId() . PHP_EOL; +echo 'getDescription: ' . $payOrder->getDescription() . PHP_EOL; +echo 'getReference: ' . $payOrder->getReference() . PHP_EOL; +echo 'getManualTransferCode: ' . $payOrder->getManualTransferCode() . PHP_EOL; +echo 'getOrderId: ' . $payOrder->getOrderId() . PHP_EOL; +echo 'getPaymentUrl: ' . '' . $payOrder->getPaymentUrl() . '' . PHP_EOL; +echo 'getStatusUrl: ' . $payOrder->getStatusUrl() . PHP_EOL; +echo 'getAmount value: ' . $payOrder->getAmount() . PHP_EOL; +echo 'getAmount currency: ' . $payOrder->getCurrency() . PHP_EOL; +echo 'getUuid: ' . $payOrder->getUuid() . PHP_EOL; +echo 'expiresAt: ' . $payOrder->getExpiresAt() . PHP_EOL; +echo 'createdAt: ' . $payOrder->getCreatedAt() . PHP_EOL; +echo 'createdBy: ' . $payOrder->getCreatedBy() . PHP_EOL; +echo 'getCreatedAt: ' . $payOrder->getCreatedAt() . PHP_EOL; +echo 'modifiedAt: ' . $payOrder->getModifiedAt() . PHP_EOL; +echo 'modifiedBy: ' . $payOrder->getModifiedBy() . PHP_EOL; diff --git a/samples/OrderCreateFastCheckout.php b/samples/OrderCreateFastCheckout.php index aa2ee0b..8303978 100644 --- a/samples/OrderCreateFastCheckout.php +++ b/samples/OrderCreateFastCheckout.php @@ -39,7 +39,7 @@ $request->setConfig($config); try { - $transaction = $request->start(); + $payOrder = $request->start(); } catch (PayException $e) { echo ''; echo 'Technical message: ' . $e->getMessage() . PHP_EOL; @@ -51,20 +51,20 @@ echo ''; echo 'Success, values:' . PHP_EOL; -echo 'getId: ' . $transaction->getId() . PHP_EOL; -echo 'getServiceId: ' . $transaction->getServiceId() . PHP_EOL; -echo 'getDescription: ' . $transaction->getDescription() . PHP_EOL; -echo 'getReference: ' . $transaction->getReference() . PHP_EOL; -echo 'getManualTransferCode: ' . $transaction->getManualTransferCode() . PHP_EOL; -echo 'getOrderId: ' . $transaction->getOrderId() . PHP_EOL; -echo 'getPaymentUrl: ' . '' . $transaction->getPaymentUrl() . '' . PHP_EOL; -echo 'getStatusUrl: ' . $transaction->getStatusUrl() . PHP_EOL; -echo 'getAmount value: ' . $transaction->getAmount()->getValue() . PHP_EOL; -echo 'getAmount currency: ' . $transaction->getAmount()->getCurrency() . PHP_EOL; -echo 'getUuid: ' . $transaction->getUuid() . PHP_EOL; -echo 'expiresAt: ' . $transaction->getExpiresAt() . PHP_EOL; -echo 'createdAt: ' . $transaction->getCreatedAt() . PHP_EOL; -echo 'createdBy: ' . $transaction->getCreatedBy() . PHP_EOL; -echo 'getCreatedAt: ' . $transaction->getCreatedAt() . PHP_EOL; -echo 'modifiedAt: ' . $transaction->getModifiedAt() . PHP_EOL; -echo 'modifiedBy: ' . $transaction->getModifiedBy() . PHP_EOL; +echo 'getId: ' . $payOrder->getId() . PHP_EOL; +echo 'getServiceId: ' . $payOrder->getServiceId() . PHP_EOL; +echo 'getDescription: ' . $payOrder->getDescription() . PHP_EOL; +echo 'getReference: ' . $payOrder->getReference() . PHP_EOL; +echo 'getManualTransferCode: ' . $payOrder->getManualTransferCode() . PHP_EOL; +echo 'getOrderId: ' . $payOrder->getOrderId() . PHP_EOL; +echo 'getPaymentUrl: ' . '' . $payOrder->getPaymentUrl() . '' . PHP_EOL; +echo 'getStatusUrl: ' . $payOrder->getStatusUrl() . PHP_EOL; +echo 'getAmount value: ' . $payOrder->getAmount() . PHP_EOL; +echo 'getAmount currency: ' . $payOrder->getAmount() . PHP_EOL; +echo 'getUuid: ' . $payOrder->getUuid() . PHP_EOL; +echo 'expiresAt: ' . $payOrder->getExpiresAt() . PHP_EOL; +echo 'createdAt: ' . $payOrder->getCreatedAt() . PHP_EOL; +echo 'createdBy: ' . $payOrder->getCreatedBy() . PHP_EOL; +echo 'getCreatedAt: ' . $payOrder->getCreatedAt() . PHP_EOL; +echo 'modifiedAt: ' . $payOrder->getModifiedAt() . PHP_EOL; +echo 'modifiedBy: ' . $payOrder->getModifiedBy() . PHP_EOL; diff --git a/samples/OrderCreateMinimal.php b/samples/OrderCreateMinimal.php index f25f4d4..0ce0d68 100644 --- a/samples/OrderCreateMinimal.php +++ b/samples/OrderCreateMinimal.php @@ -21,7 +21,7 @@ $request->setConfig($config); try { - $transaction = $request->start(); + $payOrder = $request->start(); } catch (PayException $e) { echo ''; echo 'Technical message: ' . $e->getMessage() . PHP_EOL; @@ -33,4 +33,5 @@ echo ''; echo 'Success, values:' . PHP_EOL; -echo 'getPaymentUrl: ' . '' . $transaction->getPaymentUrl() . '' . PHP_EOL; +echo 'getOrderId: ' . $payOrder->getOrderId() . PHP_EOL; +echo 'getPaymentUrl: ' . '' . $payOrder->getPaymentUrl() . '' . PHP_EOL; diff --git a/samples/OrderCreatePin.php b/samples/OrderCreatePin.php index 4f53a6d..fcdf231 100644 --- a/samples/OrderCreatePin.php +++ b/samples/OrderCreatePin.php @@ -92,7 +92,7 @@ $request->setConfig($config); try { - $transaction = $request->start(); + $payOrder = $request->start(); } catch (PayException $e) { echo ''; echo 'Technical message: ' . $e->getMessage() . PHP_EOL; @@ -104,5 +104,5 @@ echo ''; echo 'Success, values:' . PHP_EOL; -echo 'getId: ' . $transaction->getId() . PHP_EOL; -echo 'getPaymentUrl: ' . '' . $transaction->getPaymentUrl() . '' . PHP_EOL; \ No newline at end of file +echo 'getId: ' . $payOrder->getId() . PHP_EOL; +echo 'getPaymentUrl: ' . '' . $payOrder->getPaymentUrl() . '' . PHP_EOL; \ No newline at end of file diff --git a/samples/OrderDecline.php b/samples/OrderDecline.php index 6ccc5ee..fc424eb 100644 --- a/samples/OrderDecline.php +++ b/samples/OrderDecline.php @@ -20,7 +20,7 @@ $orderDeclineRequest->setConfig($config); try { - $transaction = $orderDeclineRequest->start(); + $payOrder = $orderDeclineRequest->start(); } catch (PayException $e) { echo ''; echo 'Technical message: ' . $e->getMessage() . PHP_EOL; @@ -32,20 +32,17 @@ echo ''; echo 'Success, values:' . PHP_EOL; -echo 'getOrderId: ' . $transaction->getId() . PHP_EOL; -echo 'getTransactionId: ' . $transaction->getOrderId() . PHP_EOL; -echo 'getDescription: ' . $transaction->getDescription() . PHP_EOL; -echo 'getReference: ' . $transaction->getReference() . PHP_EOL; -echo 'getAmount getValue: ' . $transaction->getAmount()->getValue() . PHP_EOL; -echo 'getAmount getCurrency: ' . $transaction->getAmount()->getCurrency() . PHP_EOL; -echo 'getAuthorizedAmount getCurrency: ' . $transaction->getAuthorizedAmount()->getCurrency() . PHP_EOL; -echo 'getAuthorizedAmount getValue: ' . $transaction->getAuthorizedAmount()->getValue() . PHP_EOL; -echo 'getStatus:' . print_r($transaction->getStatus(), true) . PHP_EOL; -echo 'getPaymentData:' . print_r($transaction->getPayments(), true) . PHP_EOL; -echo 'getIntegration:' . print_r($transaction->getIntegration(), true) . PHP_EOL; -echo 'getExpiresAt: ' . $transaction->getExpiresAt() . PHP_EOL; -echo 'getCreatedAt: ' . $transaction->getCreatedAt() . PHP_EOL; -echo 'getCreatedBy: ' . $transaction->getCreatedBy() . PHP_EOL; -echo 'getModifiedAt: ' . $transaction->getModifiedAt() . PHP_EOL; -echo 'getModifiedBy: ' . $transaction->getModifiedBy() . PHP_EOL; - +echo 'getOrderId: ' . $payOrder->getId() . PHP_EOL; +echo 'getTransactionId: ' . $payOrder->getOrderId() . PHP_EOL; +echo 'getServiceId: ' . $payOrder->getServiceId() . PHP_EOL; +echo 'getDescription: ' . $payOrder->getDescription() . PHP_EOL; +echo 'getReference: ' . $payOrder->getReference() . PHP_EOL; +echo 'getAmount getValue: ' . $payOrder->getAmount() . PHP_EOL; +echo 'getAmount getCurrency: ' . $payOrder->getCurrency() . PHP_EOL; +echo 'getStatus:' . print_r($payOrder->getStatus(), true) . PHP_EOL; +echo 'getTestmode: ' . ($payOrder->isTestmode() === true ? 'test order' : 'live order') . PHP_EOL; +echo 'getExpiresAt: ' . $payOrder->getExpiresAt() . PHP_EOL; +echo 'getCreatedAt: ' . $payOrder->getCreatedAt() . PHP_EOL; +echo 'getCreatedBy: ' . $payOrder->getCreatedBy() . PHP_EOL; +echo 'getModifiedAt: ' . $payOrder->getModifiedAt() . PHP_EOL; +echo 'getModifiedBy: ' . $payOrder->getModifiedBy() . PHP_EOL; diff --git a/samples/OrderStatus.php b/samples/OrderStatus.php index ccc8ae3..4bd5b72 100644 --- a/samples/OrderStatus.php +++ b/samples/OrderStatus.php @@ -17,7 +17,7 @@ $request->setConfig($config); try { - $transaction = $request->start(); + $payOrder = $request->start(); } catch (PayException $e) { echo ''; echo 'Technical message: ' . $e->getMessage() . PHP_EOL; @@ -30,23 +30,21 @@ echo ''; echo 'Success, values:' . PHP_EOL.PHP_EOL; -echo 'isPending: ' . ($transaction->isPending() ? 'YES' : 'no') . PHP_EOL; -echo 'isPaid: ' . ($transaction->isPaid() ? 'YES' : 'no') . PHP_EOL; -echo 'isAuthorized: ' . ($transaction->isAuthorized() ? 'YES' : 'no') . PHP_EOL; -echo 'isCancelled: ' . ($transaction->isCancelled() ? 'YES' : 'no') . PHP_EOL; -echo 'isBeingVerified: ' . ($transaction->isBeingVerified() ? 'YES' : 'no') . PHP_EOL; -echo 'isChargeBack: ' . ($transaction->isChargeBack() ? 'YES' : 'no') . PHP_EOL; -echo 'isPartialPayment: ' . ($transaction->isPartialPayment() ? 'YES' : 'no') . PHP_EOL; -echo 'isRefunded: ' . ($transaction->isRefunded() ? 'YES' : 'no') . PHP_EOL; -echo 'isPartiallyRefunded: ' . ($transaction->isPartiallyRefunded() ? 'YES' : 'no') . PHP_EOL . PHP_EOL; -echo 'getStatusCode: ' . $transaction->getStatusCode() . PHP_EOL; -echo 'getStatusName: ' . $transaction->getStatusName() . PHP_EOL; -echo 'getId: ' . $transaction->getId() . PHP_EOL; -echo 'getOrderId: ' . $transaction->getOrderId() . PHP_EOL; -echo 'getServiceCode: ' . $transaction->getServiceCode() . PHP_EOL; -echo 'getDescription: ' . $transaction->getDescription() . PHP_EOL; -echo 'getReference: ' . $transaction->getReference() . PHP_EOL; -echo 'getIpAddress: ' . $transaction->getIpAddress() . PHP_EOL.PHP_EOL; -echo 'getAmount: ' . $transaction->getAmount() . PHP_EOL; -echo 'getCurrency: ' . $transaction->getCurrency() . PHP_EOL; -echo 'paymentMethod: ' . $transaction->getPaymentMethod() . PHP_EOL; \ No newline at end of file +echo 'isPending: ' . ($payOrder->isPending() ? 'YES' : 'no') . PHP_EOL; +echo 'isPaid: ' . ($payOrder->isPaid() ? 'YES' : 'no') . PHP_EOL; +echo 'isAuthorized: ' . ($payOrder->isAuthorized() ? 'YES' : 'no') . PHP_EOL; +echo 'isCancelled: ' . ($payOrder->isCancelled() ? 'YES' : 'no') . PHP_EOL; +echo 'isBeingVerified: ' . ($payOrder->isBeingVerified() ? 'YES' : 'no') . PHP_EOL; +echo 'isChargeBack: ' . ($payOrder->isChargeBack() ? 'YES' : 'no') . PHP_EOL; +echo 'isPartialPayment: ' . ($payOrder->isPartialPayment() ? 'YES' : 'no') . PHP_EOL; +echo 'isRefunded: ' . ($payOrder->isRefunded() ? 'YES' : 'no') . PHP_EOL; +echo 'isPartiallyRefunded: ' . ($payOrder->isRefundedPartial() ? 'YES' : 'no') . PHP_EOL . PHP_EOL; +echo 'getStatusCode: ' . $payOrder->getStatusCode() . PHP_EOL; +echo 'getStatusName: ' . $payOrder->getStatusName() . PHP_EOL; +echo 'getId: ' . $payOrder->getId() . PHP_EOL; +echo 'getOrderId: ' . $payOrder->getOrderId() . PHP_EOL; +echo 'getDescription: ' . $payOrder->getDescription() . PHP_EOL; +echo 'getReference: ' . $payOrder->getReference() . PHP_EOL; +echo 'getAmount: ' . $payOrder->getAmount(). PHP_EOL; +echo 'getCurrency: ' . $payOrder->getCurrency() . PHP_EOL; +echo 'paymentMethod: ' . $payOrder->getPaymentMethod() . PHP_EOL; \ No newline at end of file diff --git a/samples/OrderUpdate.php b/samples/OrderUpdate.php new file mode 100644 index 0000000..8fede28 --- /dev/null +++ b/samples/OrderUpdate.php @@ -0,0 +1,35 @@ +setUsername($_REQUEST['username'] ?? ''); +$config->setPassword($_REQUEST['password'] ?? ''); + +$transactionId = $_REQUEST['pay_order_id'] ?? exit('Pass transactionId'); + +$orderApproveRequest = new OrderUpdateRequest($transactionId); +$orderApproveRequest->setDescription('desc12345'); +$orderApproveRequest->setReference('12345'); + +try { + $payOrder = $orderApproveRequest->setConfig($config)->start(); +} catch (PayException $e) { + if ($e->getCode() == 204) { + echo 'success'; + } else { + echo ''; + echo 'Technical message: ' . $e->getMessage() . PHP_EOL; + echo 'Pay-code: ' . $e->getPayCode() . PHP_EOL; + echo 'Customer message: ' . $e->getFriendlyMessage() . PHP_EOL; + echo 'HTTP-code: ' . $e->getCode() . PHP_EOL; + } + exit(); +} \ No newline at end of file diff --git a/samples/OrderVoid.php b/samples/OrderVoid.php index 0a21f2e..da79278 100644 --- a/samples/OrderVoid.php +++ b/samples/OrderVoid.php @@ -21,7 +21,7 @@ try { - $capture = $orderVoidRequest->start(); + $payOrder = $orderVoidRequest->start(); } catch (PayException $e) { echo ''; echo 'Technical message: ' . $e->getMessage() . PHP_EOL; @@ -33,20 +33,17 @@ echo ''; echo 'Success, values:' . PHP_EOL; -echo 'getOrderId: ' . $capture->getId() . PHP_EOL; -echo 'getTransactionId: ' . $capture->getOrderId() . PHP_EOL; -echo 'getServiceCode: ' . $capture->getServiceCode() . PHP_EOL; -echo 'getDescription: ' . $capture->getDescription() . PHP_EOL; -echo 'getReference: ' . $capture->getReference() . PHP_EOL; -echo 'getIpAddress: ' . $capture->getIpAddress() . PHP_EOL; -echo 'getAmount getValue: ' . $capture->getAmount()->getValue() . PHP_EOL; -echo 'getAmount getCurrency: ' . $capture->getAmount()->getCurrency() . PHP_EOL; -echo 'getStatus:' . print_r($capture->getStatus(), true) . PHP_EOL; -echo 'getIntegration:' . print_r($capture->getIntegration(), true) . PHP_EOL; -echo 'getExpiresAt: ' . $capture->getExpiresAt() . PHP_EOL; -echo 'getCreatedAt: ' . $capture->getCreatedAt() . PHP_EOL; -echo 'getCreatedBy: ' . $capture->getCreatedBy() . PHP_EOL; -echo 'getModifiedAt: ' . $capture->getModifiedAt() . PHP_EOL; -echo 'getModifiedBy: ' . $capture->getModifiedBy() . PHP_EOL; -echo 'getDeletedAt: ' . $capture->getDeletedAt() . PHP_EOL; -echo 'getDeletedBy: ' . $capture->getDeletedBy() . PHP_EOL; \ No newline at end of file +echo 'getOrderId: ' . $payOrder->getId() . PHP_EOL; +echo 'getTransactionId: ' . $payOrder->getOrderId() . PHP_EOL; +echo 'getServiceCode: ' . $payOrder->getServiceId() . PHP_EOL; +echo 'getDescription: ' . $payOrder->getDescription() . PHP_EOL; +echo 'getReference: ' . $payOrder->getReference() . PHP_EOL; +echo 'getAmount getValue: ' . $payOrder->getAmount() . PHP_EOL; +echo 'getAmount getCurrency: ' . $payOrder->getCurrency() . PHP_EOL; +echo 'getStatus:' . print_r($payOrder->getStatus(), true) . PHP_EOL; +echo 'getTestmode: ' . ($payOrder->isTestmode() === true ? 'test order' : 'live order') . PHP_EOL; +echo 'getExpiresAt: ' . $payOrder->getExpiresAt() . PHP_EOL; +echo 'getCreatedAt: ' . $payOrder->getCreatedAt() . PHP_EOL; +echo 'getCreatedBy: ' . $payOrder->getCreatedBy() . PHP_EOL; +echo 'getModifiedAt: ' . $payOrder->getModifiedAt() . PHP_EOL; +echo 'getModifiedBy: ' . $payOrder->getModifiedBy() . PHP_EOL; diff --git a/samples/TransactionStatus.php b/samples/TransactionStatus.php index 2389a00..e3c5f8b 100644 --- a/samples/TransactionStatus.php +++ b/samples/TransactionStatus.php @@ -14,7 +14,7 @@ $config = (new Config())->setUsername($_REQUEST['username'] ?? '')->setPassword($_REQUEST['password'] ?? ''); try { - $transaction = (new TransactionStatusRequest($orderId))->setConfig($config)->start(); + $payOrder = (new TransactionStatusRequest($orderId))->setConfig($config)->start(); } catch (PayException $e) { echo ''; echo 'Technical message: ' . $e->getMessage() . PHP_EOL; @@ -27,37 +27,23 @@ echo ''; echo 'Success, values:' . PHP_EOL.PHP_EOL; -echo 'isPending: ' . ($transaction->isPending() ? 'YES' : 'no') . PHP_EOL; -echo 'isPaid: ' . ($transaction->isPaid() ? 'YES' : 'no') . PHP_EOL; -echo 'isAuthorized: ' . ($transaction->isAuthorized() ? 'YES' : 'no') . PHP_EOL; -echo 'isCancelled: ' . ($transaction->isCancelled() ? 'YES' : 'no') . PHP_EOL; -echo 'isBeingVerified: ' . ($transaction->isBeingVerified() ? 'YES' : 'no') . PHP_EOL; -echo 'isChargeBack: ' . ($transaction->isChargeBack() ? 'YES' : 'no') . PHP_EOL; -echo 'isPartialPayment: ' . ($transaction->isPartialPayment() ? 'YES' : 'no') . PHP_EOL; -echo 'isRefunded: ' . ($transaction->isRefunded() ? 'YES' : 'no') . PHP_EOL; -echo 'isPartiallyRefunded: ' . ($transaction->isPartiallyRefunded() ? 'YES' : 'no') . PHP_EOL . PHP_EOL; - -echo 'getStatusCode: ' . $transaction->getStatusCode() . PHP_EOL; -echo 'getStatusName: ' . $transaction->getStatusName() . PHP_EOL; -echo 'getId: ' . $transaction->getId() . PHP_EOL; -echo 'getOrderId: ' . $transaction->getOrderId() . PHP_EOL; -echo 'getServiceCode: ' . $transaction->getServiceCode() . PHP_EOL; -echo 'getDescription: ' . $transaction->getDescription() . PHP_EOL; -echo 'getReference: ' . $transaction->getReference() . PHP_EOL; -echo 'getIpAddress: ' . $transaction->getIpAddress() . PHP_EOL.PHP_EOL; -echo 'getAmount: ' . $transaction->getAmount() . PHP_EOL; -echo 'getCurrency: ' . $transaction->getCurrency() . PHP_EOL; - -echo 'getAmountConverted: ' . $transaction->getAmountConverted() . PHP_EOL; -echo 'getAmountConvertedCurrency: ' . $transaction->getAmountConvertedCurrency() . PHP_EOL; -echo 'getAmountPaid: ' . $transaction->getAmountPaid() . PHP_EOL; -echo 'getAmountPaidCurrency: ' . $transaction->getAmountPaidCurrency() . PHP_EOL; -echo 'getAmountRefunded: ' . $transaction->getAmountRefunded() . PHP_EOL; -echo 'getAmountRefundedCurrency: ' . $transaction->getAmountRefundedCurrency() . PHP_EOL.PHP_EOL; - -echo 'paymentMethod: ' . $transaction->getPaymentMethod()['id'] . PHP_EOL; -echo 'getPaymentProfileId: ' . $transaction->getPaymentProfileId() . PHP_EOL; -echo 'integration: ' . ($transaction->getIntegration()['testMode'] === true ? '1' : 0) . PHP_EOL; -echo 'expiresAt: ' . $transaction->getExpiresAt() . PHP_EOL; -echo 'createdAt: ' . $transaction->getCreatedAt() . PHP_EOL; -print_r($transaction->getPaymentData()); +echo 'isPending: ' . ($payOrder->isPending() ? 'YES' : 'no') . PHP_EOL; +echo 'isPaid: ' . ($payOrder->isPaid() ? 'YES' : 'no') . PHP_EOL; +echo 'isAuthorized: ' . ($payOrder->isAuthorized() ? 'YES' : 'no') . PHP_EOL; +echo 'isCancelled: ' . ($payOrder->isCancelled() ? 'YES' : 'no') . PHP_EOL; +echo 'isBeingVerified: ' . ($payOrder->isBeingVerified() ? 'YES' : 'no') . PHP_EOL; +echo 'isChargeBack: ' . ($payOrder->isChargeBack() ? 'YES' : 'no') . PHP_EOL; +echo 'isPartialPayment: ' . ($payOrder->isPartialPayment() ? 'YES' : 'no') . PHP_EOL; +echo 'isRefunded: ' . ($payOrder->isRefunded() ? 'YES' : 'no') . PHP_EOL; +echo 'isPartiallyRefunded: ' . ($payOrder->isRefundedPartial() ? 'YES' : 'no') . PHP_EOL . PHP_EOL; +echo 'getStatusCode: ' . $payOrder->getStatusCode() . PHP_EOL; +echo 'getStatusName: ' . $payOrder->getStatusName() . PHP_EOL; +echo 'getId: ' . $payOrder->getId() . PHP_EOL; +echo 'getOrderId: ' . $payOrder->getOrderId() . PHP_EOL; +echo 'getDescription: ' . $payOrder->getDescription() . PHP_EOL; +echo 'getReference: ' . $payOrder->getReference() . PHP_EOL; +echo 'getAmount: ' . $payOrder->getAmount() . PHP_EOL; +echo 'getCurrency: ' . $payOrder->getCurrency() . PHP_EOL; +echo 'integration: ' . ($payOrder->getIntegration()['testMode'] === true ? '1' : 0) . PHP_EOL; +echo 'expiresAt: ' . $payOrder->getExpiresAt() . PHP_EOL; +echo 'createdAt: ' . $payOrder->getCreatedAt() . PHP_EOL; diff --git a/src/Config/Config.php b/src/Config/Config.php index 3d010fe..a334f0f 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -300,6 +300,17 @@ public function getDebug(): bool return $this->data['debug'] == 1; } + /** + * @return string + */ + public function getFailoverUrl(): string + { + if (!empty($this->data['failoverUrl'])) { + return trim($this->data['failoverUrl']); + } + return ''; + } + /** * Set destination(core) url * @@ -676,6 +687,17 @@ public function getDebug(): bool return $this->data['debug'] == 1; } + /** + * @return string + */ + public function getFailoverUrl(): string + { + if (!empty($this->data['failoverUrl'])) { + return trim($this->data['failoverUrl']); + } + return ''; + } + /** * Set destination(core) url * diff --git a/src/Mapper/ConfigProvider.php b/src/Mapper/ConfigProvider.php index e109053..ded3a4e 100644 --- a/src/Mapper/ConfigProvider.php +++ b/src/Mapper/ConfigProvider.php @@ -82,18 +82,17 @@ public function getMap(): array 'GetIpAddresses' => 'IpAddresses', 'TerminalPaymentStatus' => 'TerminalPaymentStatus', 'TerminalCancelPayment' => 'TerminalPaymentStatus', - 'CancelTransaction' => 'Transaction', 'DeclineTransaction' => 'Transaction', - 'TokenizeTransaction' => 'Transaction', 'TransactionRefund' => 'TransactionRefundResponse', - 'TransactionStatus' => 'TransactionStatusResponse', - 'OrderCreate' => 'OrderCreateResponse', - 'OrderCapture' => 'OrderCaptureResponse', - 'OrderVoid' => 'OrderVoidResponse', - 'OrderAbort' => 'OrderAbortResponse', - 'orderStatus' => 'OrderStatusResponse', - 'orderApprove' => 'OrderApproveResponse', - 'orderDecline' => 'OrderDeclineResponse', + 'TransactionStatus' => 'PayOrder', + 'OrderCreate' => 'PayOrder', + 'OrderCapture' => 'PayOrder', + 'OrderVoid' => 'PayOrder', + 'OrderAbort' => 'PayOrder', + 'OrderStatus' => 'PayOrder', + 'OrderUpdate' => 'PayOrder', + 'OrderApprove' => 'PayOrder', + 'OrderDecline' => 'PayOrder', 'TerminalsGet' => 'Terminal', 'TerminalsBrowse' => 'Terminals' ], diff --git a/src/Model/Amount.php b/src/Model/Amount.php index e94e9fa..0ddc70a 100644 --- a/src/Model/Amount.php +++ b/src/Model/Amount.php @@ -28,6 +28,20 @@ class Amount implements ModelInterface, JsonSerializable */ protected $currency = 'EUR'; + /** + * @param int|null $value + * @param string|null $currency + */ + public function __construct(int $value = null, string $currency = null) + { + if (!is_null($value)) { + $this->setValue($value); + } + if (!is_null($currency)) { + $this->setCurrency($currency); + } + } + /** * @return string */ diff --git a/src/Model/ConfigProvider.php b/src/Model/ConfigProvider.php index cfe8840..83a2d09 100644 --- a/src/Model/ConfigProvider.php +++ b/src/Model/ConfigProvider.php @@ -191,6 +191,8 @@ public function getModelConfig(): array 'OrderAbortResponse' => Response\OrderAbortResponse::class, 'ServiceGetConfigResponse' => Response\ServiceGetConfigResponse::class, + 'PayOrder' => Pay\PayOrder::class, + 'CheckoutOptions' => CheckoutOptions::class, 'CheckoutOption' => CheckoutOption::class, 'Method' => Method::class, diff --git a/src/Model/Pay/PayLoad.php b/src/Model/Pay/PayLoad.php index c1ee173..8618a4b 100644 --- a/src/Model/Pay/PayLoad.php +++ b/src/Model/Pay/PayLoad.php @@ -6,7 +6,8 @@ class PayLoad { - protected float $amount; + protected int $amount; + protected string $currency; protected float $amountCap; protected float $amountAuth; protected string $reference; @@ -24,7 +25,8 @@ class PayLoad */ public function __construct(array $payload) { - $this->amount = (float)$payload['amount']; + $this->amount = (int)$payload['amount']; + $this->currency = (string)$payload['currency']; $this->amountCap = (float)$payload['amount_cap']; $this->amountAuth = (float)$payload['amount_auth']; $this->reference = (string)$payload['reference']; @@ -95,13 +97,21 @@ public function nce(): string } /** - * @return float + * @return int */ - public function getAmount(): float + public function getAmount(): int { return $this->amount; } + /** + * @return string + */ + public function getCurrency(): string + { + return $this->currency; + } + /** * @return float */ diff --git a/src/Model/Pay/PayOrder.php b/src/Model/Pay/PayOrder.php index a92184b..7537262 100644 --- a/src/Model/Pay/PayOrder.php +++ b/src/Model/Pay/PayOrder.php @@ -4,42 +4,146 @@ namespace PayNL\Sdk\Model\Pay; +use PayNL\Sdk\Model\ModelInterface; +use PayNL\Sdk\Model\Amount; use PayNL\Sdk\Model\Pay\PayStatus; -class PayOrder +/** + * Class PayOrder + * + * @package PayNL\Sdk\Model + */ +class PayOrder implements ModelInterface { - private int $stateId = 0; - private array $processedPayload; - private string $message; - private array $payload = []; - private $id; - private $uuid; - private $amount; - private $status; - private $orderId; - private $receipt; - private $payments; - private $reference; - private $description; - private $integration; - private $checkoutData; - private $capturedAmount; - private $authorizedAmount; - private $manualTransferCode; + /** + * @var int + */ + private int $stateId; + + /** + * @var string + */ + protected string $id; + + /** + * @var string + */ + protected string $serviceId; + + /** + * @var string + */ + protected $description; + + /** + * @var string + */ + protected $reference; + + /** + * @var string + */ + protected $manualTransferCode; + + /** + * @var string + */ + protected $orderId; + + /** + * @var string + */ + protected $uuid; + + /** + * @var string + */ + protected $customerKey; + + /** + * @var array + */ + protected $status; + + /** + * @var string + */ + protected $receipt; + + /** + * @var array + */ + protected $integration; + + /** + * @var Amount + */ + protected $amount; + + /** + * @var Amount + */ + protected $authorizedAmount; + + /** + * @var Amount + */ + protected $capturedAmount; /** - * @var mixed + * @var Object */ - private $paymentProfileId; + protected $checkoutData; /** - * @param $payload + * @var array */ - public function __construct($payload) + protected $payments; + + /** + * @var string + */ + protected $createdAt; + + /** + * @var string + */ + protected $createdBy; + + /** + * @var string + */ + protected $modifiedAt; + + /** + * @var string + */ + protected $modifiedBy; + + /** + * @var string + */ + protected $expiresAt; + + /** + * @var string + */ + protected $completedAt; + + /** + * @var array + */ + protected $links; + + + public function __construct($payload = null) { - if (!empty($payload)) { - foreach ($payload as $_key => $_val) { + if (!empty($payload['object'])) { + foreach ($payload['object'] as $_key => $_val) { + if (in_array($_key, ['amount', 'capturedAmount', 'authorizedAmount'])) { + continue; + } $method = 'set' . ucfirst((string)$_key); if (method_exists($this, $method)) { $this->$method($_val); @@ -48,61 +152,177 @@ public function __construct($payload) } } + /** - * @return bool + * @return int */ - public function failed() + public function getStatusCode(): int { - return $this->stateId === 0; + return (int)($this->status['code'] ?? 0); } /** - * @param $p + * @return string + */ + public function getStatusName(): string + { + return (string)($this->status['action'] ?? ''); + } + + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $id * @return $this */ - public function setPaymentProfileId($p) + public function setId(string $id): self { - $this->paymentProfileId = $p; + $this->id = $id; return $this; } /** - * @return mixed + * @return string */ - public function getPaymentProfileId() + public function getServiceId(): string { - return $this->paymentProfileId; + return $this->serviceId; } /** - * @return int|mixed + * @param string $serviceId + * @return $this */ - public function getLastUsedProfileId() + public function setServiceId(string $serviceId): self { - $lastUsed = 0; - foreach ($this->payload['payments'] as $payment) { - $lastUsed = $payment['paymentMethod']['id']; - } + $this->serviceId = $serviceId; + return $this; + } - return $lastUsed; + /** + * @return string + */ + public function getDescription(): string + { + return (string)$this->description; } /** - * @return bool + * @param string $description + * @return $this + */ + public function setDescription(string $description): self + { + $this->description = $description; + return $this; + } + + /** + * @return string + */ + public function getReference(): string + { + return (string)$this->reference; + } + + /** + * @param string $reference + * @return $this + */ + public function setReference(string $reference): self + { + $this->reference = $reference; + return $this; + } + + /** + * @return string + */ + public function getManualTransferCode(): string + { + return $this->manualTransferCode; + } + + /** + * @param string $manualTransferCode + * @return $this + */ + public function setManualTransferCode(string $manualTransferCode): self + { + $this->manualTransferCode = $manualTransferCode; + return $this; + } + + /** + * @return string + */ + public function getOrderId(): string + { + return $this->orderId; + } + + /** + * @param string $orderId + * @return $this */ - public function isFastCheckout() + public function setOrderId(string $orderId): self { - return !empty($this->processedPayload['checkoutData'] ?? []); + $this->orderId = $orderId; + return $this; + } + + /** + * @return string + */ + public function getUuid(): string + { + return $this->uuid; + } + + /** + * @param string $uuid + * @return $this + */ + public function setUuid(string $uuid): self + { + $this->uuid = $uuid; + return $this; + } + + /** + * @return string + */ + public function getCustomerKey(): string + { + return $this->customerKey; + } + + /** + * @param string $customerKey + * @return $this + */ + public function setCustomerKey(string $customerKey): self + { + $this->customerKey = $customerKey; + return $this; } /** * @return array */ - public function getCheckoutData() + public function getStatus(): array { - return (array)$this->processedPayload['checkoutData'] ?? []; + return $this->status; } + /** * @return int */ @@ -112,264 +332,411 @@ public function getStateId(): int } /** - * @param $stateId + * @param $stateId + * @param $name * @return void */ - public function setStateId($stateId): void + public function setStatusCodeName($stateId, $name): void { - $this->stateId = $stateId; + $this->status = ['code' => $stateId, 'action' => $name]; + } + + /** + * @param array $status + * @return $this + */ + public function setStatus(array $status): self + { + $this->status = $status; + return $this; } /** * @return string */ - public function getReference(): string + public function getReceipt(): string { - return (string)$this->reference; + return $this->receipt; } /** - * @param string $reference - * @return void + * @param string $receipt + * @return $this */ - public function setReference(string $reference): void + public function setReceipt(string $receipt): self { - $this->reference = $reference; + $this->receipt = $receipt; + return $this; + } + + /** + * @return bool + */ + public function isTestmode(): bool + { + $testmodeEnabled = $this->integration['test'] ?? false; + return $testmodeEnabled === true; } /** * @return array */ - public function getProcessedPayload(): array + public function getIntegration(): array { - return $this->processedPayload; + return $this->integration; } /** - * @return bool + * @param array $integration + * @return $this */ - public function isPaid() + public function setIntegration(array $integration): self { - return $this->stateId === PayStatus::PAID; + $this->integration = $integration; + return $this; } /** - * @return bool + * @return float|int */ - public function isPending() + public function getAmount() { - return $this->stateId === PayStatus::PENDING; + return $this->amount->getValue() / 100; } /** - * @return bool + * @return string */ - public function isPartialPayment() + public function getCurrency(): string { - return $this->stateId === PayStatus::PARTIAL_PAYMENT; + return (string)$this->amount->getCurrency(); } + /** - * @return bool + * @return mixed|null */ - public function isAuthorized(): bool + public function getPaymentMethod() { - return $this->stateId === PayStatus::AUTHORIZE; + return $this->payments[0]['paymentMethod']['id'] ?? null; } + /** - * @return bool + * @param Amount $amount + * @return $this */ - public function isCancelled() + public function setAmount(Amount $amount): self { - return $this->stateId === PayStatus::CANCEL; + $this->amount = $amount; + return $this; } /** - * @return bool + * @return Amount */ - public function isRefundedFully() + public function getAuthorizedAmount(): Amount { - return $this->stateId === PayStatus::REFUND; + return $this->authorizedAmount; } /** - * @return bool + * @param Amount $authorizedAmount + * @return $this */ - public function isRefundedPartial() + public function setAuthorizedAmount(Amount $authorizedAmount): self { - return $this->stateId === PayStatus::PARTIAL_REFUND; + $this->authorizedAmount = $authorizedAmount; + return $this; } /** - * @return bool + * @return Amount */ - public function isBeingVerified() + public function getCapturedAmount(): Amount { - return $this->stateId === PayStatus::VERIFY; + return $this->capturedAmount; } /** - * @return string + * @param Amount $capturedAmount + * @return $this + */ + public function setCapturedAmount(Amount $capturedAmount): self + { + $this->capturedAmount = $capturedAmount; + return $this; + } + + /** + * @return Object */ - public function getMessage(): string + public function getCheckoutData(): object { - return $this->message; + return $this->checkoutData; } /** - * @param string $message + * @param Object $checkoutData * @return $this */ - public function setMessage(string $message): self + public function setCheckoutData(object $checkoutData): self { - $this->message = $message; + $this->checkoutData = $checkoutData; return $this; } /** * @return array */ - public function getPayload(): array + public function getPayments(): array { - return (array)$this->payload; + return $this->payments; } /** - * @param array $payload - * @return void + * @param array $payments + * @return $this */ - public function setPayload(array $payload): void + public function setPayments(array $payments): self { - $this->payload = $payload; + $this->payments = $payments; + return $this; } /** - * @return mixed + * @return string */ - public function getId() + public function getCreatedAt(): string { - return $this->id; + return $this->createdAt; } /** - * @param mixed $id + * @param string $createdAt + * @return $this */ - public function setId($id): void + public function setCreatedAt(string $createdAt): self { - $this->id = $id; + $this->createdAt = $createdAt; + return $this; } /** - * @return mixed + * @return string */ - public function getUuid() + public function getCreatedBy(): string { - return $this->uuid; + return $this->createdBy; } /** - * @param mixed $uuid + * @param string $createdBy + * @return $this */ - public function setUuid($uuid): void + public function setCreatedBy(string $createdBy): self { - $this->uuid = $uuid; + $this->createdBy = $createdBy; + return $this; } /** - * @return mixed + * @return string */ - public function getAmount() + public function getModifiedAt(): string { - return $this->amount; + return $this->modifiedAt; } /** - * @param mixed $amount + * @param string $modifiedAt + * @return $this */ - public function setAmount($amount): void + public function setModifiedAt(string $modifiedAt): self { - $this->amount = $amount; + $this->modifiedAt = $modifiedAt; + return $this; } /** - * @return mixed + * @return string */ - public function getStatus() + public function getModifiedBy(): string { - return $this->status; + return (string)$this->modifiedBy; } /** - * @param mixed $status + * @param string $modifiedBy + * @return $this */ - public function setStatus($status): void + public function setModifiedBy(string $modifiedBy): self { - $this->status = $status; + $this->modifiedBy = $modifiedBy; + return $this; } /** - * @return mixed + * @return string */ - public function getOrderId() + public function getExpiresAt(): string { - return $this->orderId; + return (string)$this->expiresAt; } /** - * @param mixed $orderId + * @param string $expiresAt + * @return $this */ - public function setOrderId($orderId): void + public function setExpiresAt(string $expiresAt): self { - $this->orderId = $orderId; + $this->expiresAt = $expiresAt; + return $this; } /** - * @return mixed + * @return string */ - public function getPayments() + public function getCompletedAt(): string { - return $this->payments; + return (string)$this->completedAt; } /** - * @param mixed $payments + * @param string $completedAt + * @return $this */ - public function setPayments($payments): void + public function setCompletedAt(string $completedAt): self { - $this->payments = $payments; + $this->completedAt = $completedAt; + return $this; } /** - * @return mixed + * @return array */ - public function getDescription() + public function getLinks(): array { - return $this->description; + return $this->links; } /** - * @param mixed $description + * @param array $links + * @return $this */ - public function setDescription($description): void + public function setLinks(array $links): self { - $this->description = $description; + $this->links = $links; + return $this; } /** - * @return mixed + * @return mixed|string */ - public function getCapturedAmount() + public function getPaymentUrl() { - return $this->capturedAmount; + return $this->links['redirect'] ?? ''; } /** - * @param mixed $capturedAmount + * @return mixed|string */ - public function setCapturedAmount($capturedAmount): void + public function getStatusUrl() { - $this->capturedAmount = $capturedAmount; + return $this->links['status'] ?? ''; + } + + /** + * @return bool + */ + public function isPaid() + { + return (new PayStatus)->get($this->getStatusCode()) === PayStatus::PAID; + } + + /** + * @return bool + */ + public function isPending() + { + return (new PayStatus)->get($this->getStatusCode()) === PayStatus::PENDING; + } + + /** + * @return bool + */ + public function isCancelled() + { + return (new PayStatus)->get($this->getStatusCode()) === PayStatus::CANCEL; + } + + /** + * @return bool + */ + public function isPartialPayment() + { + return (new PayStatus)->get($this->getStatusCode()) === PayStatus::PARTIAL_PAYMENT; + } + + /** + * @return bool + */ + public function isAuthorized(): bool + { + return (new PayStatus)->get($this->getStatusCode()) === PayStatus::AUTHORIZE; + } + + /** + * @return bool + */ + public function isRefundedFully() + { + return (new PayStatus)->get($this->getStatusCode()) === PayStatus::REFUND; + } + + /** + * @return bool + */ + public function isRefundedPartial() + { + return (new PayStatus)->get($this->getStatusCode()) === PayStatus::PARTIAL_REFUND; + + } + + /** + * @return bool + */ + public function isBeingVerified() + { + return (new PayStatus)->get($this->getStatusCode()) === PayStatus::VERIFY; + } + + /** + * Check whether the status of the transaction is chargeback + * + * @return bool + */ + public function isChargeBack(): bool + { + return ($this->status['action'] ?? '') === 'CHARGEBACK'; + } + + /** + * @param bool $allowPartialRefunds + * + * @return bool + */ + public function isRefunded(bool $allowPartialRefunds = true): bool + { + if ($this->isRefundedFully()) { + return true; + } + + if ($allowPartialRefunds && $this->isRefundedPartial()) { + return true; + } + + return false; } -} \ No newline at end of file +} diff --git a/src/Model/Pay/PayStatus.php b/src/Model/Pay/PayStatus.php index 6eb5c9d..ad0e91e 100644 --- a/src/Model/Pay/PayStatus.php +++ b/src/Model/Pay/PayStatus.php @@ -42,6 +42,7 @@ public function get(int $stateId) { $mapper[-70] = self::CHARGEBACK; $mapper[-71] = self::CHARGEBACK; + $mapper[-72] = self::REFUND; $mapper[-81] = self::REFUND; $mapper[-82] = self::PARTIAL_REFUND; $mapper[20] = self::PENDING; diff --git a/src/Model/Request/OrderAbortRequest.php b/src/Model/Request/OrderAbortRequest.php index 47872a3..d122c07 100644 --- a/src/Model/Request/OrderAbortRequest.php +++ b/src/Model/Request/OrderAbortRequest.php @@ -6,7 +6,7 @@ use PayNL\Sdk\Exception\PayException; use PayNL\Sdk\Request\RequestData; -use PayNL\Sdk\Model\Response\OrderAbortResponse; +use PayNL\Sdk\Model\Pay\PayOrder; use PayNL\Sdk\Request\RequestInterface; /** @@ -44,10 +44,10 @@ public function getBodyParameters(): array } /** - * @return OrderAbortResponse + * @return PayOrder * @throws PayException */ - public function start(): OrderAbortResponse + public function start(): PayOrder { return parent::start(); } diff --git a/src/Model/Request/OrderApproveRequest.php b/src/Model/Request/OrderApproveRequest.php index 8ac90a8..e2f016a 100644 --- a/src/Model/Request/OrderApproveRequest.php +++ b/src/Model/Request/OrderApproveRequest.php @@ -6,7 +6,7 @@ use PayNL\Sdk\Exception\PayException; use PayNL\Sdk\Request\RequestData; -use PayNL\Sdk\Model\Response\OrderApproveResponse; +use PayNL\Sdk\Model\Pay\PayOrder; use PayNL\Sdk\Request\RequestInterface; /** @@ -24,7 +24,7 @@ class OrderApproveRequest extends RequestData public function __construct($transactionId) { $this->transactionId = $transactionId; - parent::__construct('orderApprove', '/orders/%transactionId%/approve', RequestInterface::METHOD_PATCH); + parent::__construct('OrderApprove', '/orders/%transactionId%/approve', RequestInterface::METHOD_PATCH); } /** @@ -44,10 +44,10 @@ public function getBodyParameters(): array } /** - * @return OrderApproveResponse + * @return PayOrder * @throws PayException */ - public function start(): OrderApproveResponse + public function start(): PayOrder { return parent::start(); } diff --git a/src/Model/Request/OrderCaptureRequest.php b/src/Model/Request/OrderCaptureRequest.php index 2ef180a..3032342 100644 --- a/src/Model/Request/OrderCaptureRequest.php +++ b/src/Model/Request/OrderCaptureRequest.php @@ -6,7 +6,7 @@ use PayNL\Sdk\Exception\PayException; use PayNL\Sdk\Request\RequestData; -use PayNL\Sdk\Model\Response\OrderCaptureResponse; +use PayNL\Sdk\Model\Pay\PayOrder; use PayNL\Sdk\Request\RequestInterface; /** @@ -90,10 +90,10 @@ public function setAmount(float $amount): self } /** - * @return OrderCaptureResponse + * @return PayOrder * @throws PayException */ - public function start(): OrderCaptureResponse + public function start(): PayOrder { if ($this->mode == 'amount') { $this->uri = '/orders/%transactionId%/capture/amount'; diff --git a/src/Model/Request/OrderCreateRequest.php b/src/Model/Request/OrderCreateRequest.php index d60969f..abd722f 100644 --- a/src/Model/Request/OrderCreateRequest.php +++ b/src/Model/Request/OrderCreateRequest.php @@ -8,7 +8,7 @@ use PayNL\Sdk\Model\Customer; use PayNL\Sdk\Model\Order; use PayNL\Sdk\Model\Stats; -use PayNL\Sdk\Model\Response\OrderCreateResponse; +use PayNL\Sdk\Model\Pay\PayOrder; use PayNL\Sdk\Request\RequestData; use PayNL\Sdk\Request\RequestInterface; use PayNL\Sdk\Util\Vat; @@ -427,10 +427,10 @@ public function setTerminal(string $terminalCode): void } /** - * @return OrderCreateResponse + * @return PayOrder * @throws PayException */ - public function start(): OrderCreateResponse + public function start(): PayOrder { $this->config->setversion(1); return parent::start(); diff --git a/src/Model/Request/OrderDeclineRequest.php b/src/Model/Request/OrderDeclineRequest.php index 4bed87b..346a913 100644 --- a/src/Model/Request/OrderDeclineRequest.php +++ b/src/Model/Request/OrderDeclineRequest.php @@ -6,7 +6,7 @@ use PayNL\Sdk\Exception\PayException; use PayNL\Sdk\Request\RequestData; -use PayNL\Sdk\Model\Response\OrderDeclineResponse; +use PayNL\Sdk\Model\Pay\PayOrder; use PayNL\Sdk\Request\RequestInterface; /** @@ -24,7 +24,7 @@ class OrderDeclineRequest extends RequestData public function __construct($transactionId) { $this->transactionId = $transactionId; - parent::__construct('orderDecline', '/orders/%transactionId%/decline', RequestInterface::METHOD_PATCH); + parent::__construct('OrderDecline', '/orders/%transactionId%/decline', RequestInterface::METHOD_PATCH); } /** @@ -44,10 +44,10 @@ public function getBodyParameters(): array } /** - * @return OrderDeclineResponse + * @return PayOrder * @throws PayException */ - public function start(): OrderDeclineResponse + public function start(): PayOrder { return parent::start(); } diff --git a/src/Model/Request/OrderStatusRequest.php b/src/Model/Request/OrderStatusRequest.php index 482375e..32bf92f 100644 --- a/src/Model/Request/OrderStatusRequest.php +++ b/src/Model/Request/OrderStatusRequest.php @@ -6,7 +6,7 @@ use PayNL\Sdk\Exception\PayException; use PayNL\Sdk\Request\RequestData; -use PayNL\Sdk\Model\Response\OrderStatusResponse; +use PayNL\Sdk\Model\Pay\PayOrder; use PayNL\Sdk\Request\RequestInterface; use PayNL\Sdk\Config\Config; @@ -26,7 +26,7 @@ class OrderStatusRequest extends RequestData public function __construct(string $orderId) { $this->orderId = $orderId; - parent::__construct('orderStatus', '/orders/%transactionId%/status', RequestInterface::METHOD_GET); + parent::__construct('OrderStatus', '/orders/%transactionId%/status', RequestInterface::METHOD_GET); } public function getPathParameters(): array @@ -42,13 +42,14 @@ public function getBodyParameters(): array } /** - * @return OrderStatusResponse + * @return PayOrder * @throws PayException */ - public function start(): OrderStatusResponse + public function start(): PayOrder { # Always use TGU-1 for orderStatus $this->config->setCore(Config::TGU1); + return parent::start(); } } \ No newline at end of file diff --git a/src/Model/Request/OrderUpdateRequest.php b/src/Model/Request/OrderUpdateRequest.php new file mode 100644 index 0000000..3a70b2a --- /dev/null +++ b/src/Model/Request/OrderUpdateRequest.php @@ -0,0 +1,85 @@ +transactionId = $transactionId; + $this->description = ''; + parent::__construct('OrderUpdate', '/orders/%transactionId%', RequestInterface::METHOD_PATCH); + } + + /** + * @param string $description + * @return $this + */ + public function setDescription(string $description): self + { + $this->description = $description; + return $this; + } + + /** + * @param string $reference + * @return $this + */ + public function setReference(string $reference): self + { + $this->reference = $reference; + return $this; + } + + /** + * @return string[] + */ + public function getPathParameters(): array + { + return ['transactionId' => $this->transactionId]; + } + + /** + * @return array + */ + public function getBodyParameters(): array + { + $parameters = []; + + if (!empty($this->description)) { + $parameters['description'] = $this->description; + } + if (!empty($this->reference)) { + $parameters['reference'] = $this->reference; + } + return $parameters; + } + + /** + * @return PayOrder + * @throws PayException + */ + public function start(): PayOrder + { + return parent::start(); + } +} \ No newline at end of file diff --git a/src/Model/Request/OrderVoidRequest.php b/src/Model/Request/OrderVoidRequest.php index 6bf9aa0..c751504 100644 --- a/src/Model/Request/OrderVoidRequest.php +++ b/src/Model/Request/OrderVoidRequest.php @@ -6,7 +6,7 @@ use PayNL\Sdk\Exception\PayException; use PayNL\Sdk\Request\RequestData; -use PayNL\Sdk\Model\Response\OrderVoidResponse; +use PayNL\Sdk\Model\Pay\PayOrder; use PayNL\Sdk\Request\RequestInterface; /** @@ -44,10 +44,10 @@ public function getBodyParameters(): array } /** - * @return OrderVoidResponse + * @return PayOrder * @throws PayException */ - public function start(): OrderVoidResponse + public function start(): PayOrder { return parent::start(); } diff --git a/src/Model/Request/TransactionStatusRequest.php b/src/Model/Request/TransactionStatusRequest.php index b1783ae..6124242 100644 --- a/src/Model/Request/TransactionStatusRequest.php +++ b/src/Model/Request/TransactionStatusRequest.php @@ -6,7 +6,7 @@ use PayNL\Sdk\Exception\PayException; use PayNL\Sdk\Request\RequestData; -use PayNL\Sdk\Model\Response\TransactionStatusResponse; +use PayNL\Sdk\Model\Pay\PayOrder; use PayNL\Sdk\Request\RequestInterface; /** @@ -41,10 +41,10 @@ public function getBodyParameters(): array } /** - * @return TransactionStatusResponse + * @return PayOrder * @throws PayException */ - public function start(): TransactionStatusResponse + public function start(): PayOrder { # Always use rest.pay.nl for this status request $this->config->setCore('https://rest.pay.nl'); diff --git a/src/Request/ConfigProvider.php b/src/Request/ConfigProvider.php index 4dddcfc..e6eb622 100644 --- a/src/Request/ConfigProvider.php +++ b/src/Request/ConfigProvider.php @@ -206,6 +206,13 @@ protected function getTransactionServicesConfig(): array 'transactionId' => '', ], ], + 'OrderUpdate' => [ + 'uri' => '/', + 'method' => RequestInterface::METHOD_PATCH, + 'requiredParams' => [ + 'transactionId' => '', + ], + ], 'OrderCapture' => [ 'uri' => '', 'requiredParams' => [ @@ -236,34 +243,27 @@ protected function getTransactionServicesConfig(): array 'transactionId' => '', ], ], - 'orderStatus' => [ + 'OrderStatus' => [ 'uri' => '/transactions/%transactionId%/status', 'method' => RequestInterface::METHOD_GET, 'requiredParams' => [ 'transactionId' => '', ], ], - 'orderApprove' => [ + 'OrderApprove' => [ 'uri' => '/', 'method' => RequestInterface::METHOD_PATCH, 'requiredParams' => [ 'transactionId' => '', ], ], - 'orderDecline' => [ + 'OrderDecline' => [ 'uri' => '/', 'method' => RequestInterface::METHOD_PATCH, 'requiredParams' => [ 'transactionId' => '', ], ], - 'MakeTransactionRecurring' => [ - 'uri' => '/transactions/%transactionId%/recurring', - 'method' => RequestInterface::METHOD_POST, - 'requiredParams' => [ - 'transactionId' => 'EX(-\d{4}){3,}', - ], - ], 'TransactionRefund' => [ 'uri' => '/transactions/%transactionId%/refund', 'method' => RequestInterface::METHOD_PATCH, @@ -277,20 +277,6 @@ protected function getTransactionServicesConfig(): array 'requiredParams' => [ 'transactionId' => '', ], - ], - 'TokenizeTransaction' => [ - 'uri' => '/transactions/%transactionId%/tokenize', - 'method' => RequestInterface::METHOD_PATCH, - 'requiredParams' => [ - 'transactionId' => 'EX(-\d{4}){3,}', - ], - ], - 'CancelTransaction' => [ - 'uri' => '/transactions/%transactionId%/cancel', - 'method' => RequestInterface::METHOD_PATCH, - 'requiredParams' => [ - 'transactionId' => '', - ], ] ]; } diff --git a/src/Request/RequestData.php b/src/Request/RequestData.php index 0154b4a..4be65d4 100644 --- a/src/Request/RequestData.php +++ b/src/Request/RequestData.php @@ -58,6 +58,10 @@ public function start() $config->merge($this->config); } + if (!empty($config->getFailoverUrl())) { + $config->setCore($config->getFailoverUrl()); + } + try { $response = (Application::init($config))->request($this)->run(); } catch (\Throwable $e) { diff --git a/src/Util/Exchange.php b/src/Util/Exchange.php index b9c23d8..f269f9d 100644 --- a/src/Util/Exchange.php +++ b/src/Util/Exchange.php @@ -6,6 +6,7 @@ use PayNL\Sdk\Config\Config as PayConfig; use PayNL\Sdk\Config\Config; +use PayNL\Sdk\Model\Amount; use PayNL\Sdk\Model\Request\OrderStatusRequest; use PayNL\Sdk\Model\Pay\PayStatus; use PayNL\Sdk\Model\Pay\PayOrder; @@ -171,12 +172,14 @@ public function getPayLoad() $checkoutData = $tguData['object']['checkoutData'] ?? null; $amount = $tguData['object']['amount']['value'] ?? ''; + $currency = $tguData['object']['amount']['currency'] ?? ''; $amountCap = $tguData['object']['capturedAmount']['value'] ?? ''; $amountAuth = $tguData['object']['authorizedAmount']['value'] ?? ''; } $this->payload = new PayLoad([ 'amount' => $amount ?? null, + 'currency' => $currency ?? '', 'amount_cap' => $amountCap ?? null, 'amount_auth' => $amountAuth ?? null, 'reference' => $reference, @@ -203,35 +206,35 @@ public function getPayLoad() public function process(PayConfig $config = null): PayOrder { $payload = $this->getPayload(); - $payStatus = new PayStatus(); if (empty($config)) { $config = Config::getConfig(); } - $payOrder = new PayOrder($payload->getFullPayLoad()); - $payOrder->setAmount($payload->getAmount()); - $payOrder->setPaymentProfileId($payload->getPaymentProfile()); - $payOrder->setOrderId($payload->getPayOrderId()); - $payOrder->setReference($payload->getReference()); - if ($this->isSignExchange()) { $signingResult = $this->checkSignExchange($config->getUsername(), $config->getPassword()); + if ($signingResult === true) { - $paymentState = $payload->getInternalStateId(); + dbg('signingResult true'); + $payOrder = new PayOrder($payload->getFullPayLoad()); + $payOrder->setReference($payload->getReference()); + $payOrder->setOrderId($payload->getPayOrderId()); + $payOrder->setAmount(new Amount($payload->getAmount(), $payload->getCurrency())); + #dbg((string)print_r($payOrder, true)); } else { throw new Exception('Signing request failed'); } } else { try { - $payloadState = $payStatus->get($payload->getInternalStateId()); + $payloadState = (new PayStatus())->get($payload->getInternalStateId()); } catch (\Throwable $e) { $payloadState = null; } # Not a signing request... - if ($payloadState === PayStatus::PENDING) { - $paymentState = $payload->getInternalStateId(); + if ($payloadState === PayStatus::PENDING) { + $payOrder = new PayOrder(); + $payOrder->setStatusCodeName(PayStatus::PENDING, 'PENDING'); } else { # Continue to check the order status manually try { @@ -248,12 +251,7 @@ public function process(PayConfig $config = null): PayOrder $request = new OrderStatusRequest($payload->getPayOrderId()); } - $transaction = $request->setConfig($config)->start(); - $paymentState = $transaction->getStatusCode(); - dbg('amount_payload: ' . $payload->getAmount()); - dbg('amount_trans: ' . $transaction->getAmount()); - - $payOrder->setAmount($transaction->getAmount()); + $payOrder = $request->setConfig($config)->start(); } catch (PayException $e) { dbg($e->getMessage()); @@ -262,8 +260,6 @@ public function process(PayConfig $config = null): PayOrder } } - $payOrder->setStateId($payStatus->get($paymentState)); - return $payOrder; }