From b30e12a3e19381fca06f50a79861a53863618ca4 Mon Sep 17 00:00:00 2001 From: Ronald Fiering Date: Tue, 8 Sep 2020 15:56:01 +0200 Subject: [PATCH 1/5] add Refund to ShopServerGateway --- src/Message/ShopServerRefundRequest.php | 156 +++++++++++++++++++++++ src/Message/ShopServerRefundResponse.php | 11 ++ src/ShopServerGateway.php | 8 ++ 3 files changed, 175 insertions(+) create mode 100644 src/Message/ShopServerRefundRequest.php create mode 100644 src/Message/ShopServerRefundResponse.php diff --git a/src/Message/ShopServerRefundRequest.php b/src/Message/ShopServerRefundRequest.php new file mode 100644 index 0000000..6b6174b --- /dev/null +++ b/src/Message/ShopServerRefundRequest.php @@ -0,0 +1,156 @@ +getBaseData(); + + $data['txid'] = $this->getTransactionReference(); + + $sequence_number = $this->getSequenceNumber(); + if (isset($sequence_number)) { + $data['sequencenumber'] = $sequence_number; + } + + // Amount is in minor units. + $data['amount'] = $this->getAmountInteger() * -1; + + // Currency is (i.e. has to be) ISO 4217 + $data['currency'] = $this->getCurrency(); + + $data['transactiontype'] = 'RT'; + + if ($this->getDescription()) { + $data['narrative_text'] = substr($this->getDescription(), 0, 80); + } + + if ($this->getSettleAccount()) { + $data['settleaccount'] = $this->getSettleAccount(); + } + + if ($this->getDataItems()) { + $data = array_merge($data, $this->getDataItems()); + } + + if ($this->getMerchantInvoiceId()) { + $data['invoiceid'] = $this->getMerchantInvoiceId(); + } + + if ($this->getInvoiceDeliveryMode()) { + $data['invoice_deliverymode'] = $this->getInvoiceDeliveryMode(); + } + + if ($this->getInvoiceDeliveryDate()) { + $data['invoice_deliverydate'] = $this->getInvoiceDeliveryDate(); + } + + if ($this->getInvoiceDeliveryEndDate()) { + $data['invoice_deliveryenddate'] = $this->getInvoiceDeliveryEndDate(); + } + + if ($this->getInvoiceAppendix()) { + $data['invoiceappendix'] = $this->getInvoiceAppendix(); + } + + if ($this->getMandateId()) { + $data['mandate_identification'] = $this->getMandateId(); + } + + return $data; + } + + protected function createResponse($data) + { + return $this->response = new ShopServerCaptureResponse($this, $data); + } + + /** + * The sequence number is used to capture the total in smaller amounts. + */ + public function setSequenceNumber($sequenceNumber) + { + if (!is_numeric($sequenceNumber)) { + throw new InvalidRequestException('Sequence Number must be numeric.'); + } + + return $this->setParameter('sequenceNumber', $sequenceNumber); + } + + public function getSequenceNumber() + { + return $this->getParameter('sequenceNumber'); + } + + /** + * The PAYONE gateway identifier. + */ + public function getTransactionReference() + { + return $this->getParameter('txid'); + } + + + /** + * Sets whether you want to settle the account or not. + */ + public function setSettleAccount($settleAccount) + { + // Allow tre/false/null for convenience. + if ($settleAccount === true) { + $settleAccount = static::SETTLE_ACCOUNT_YES; + } elseif ($settleAccount === false) { + $settleAccount = static::SETTLE_ACCOUNT_NO; + } elseif (!isset($settleAccount)) { + $settleAccount = static::SETTLE_ACCOUNT_AUTO; + } + + if ($settleAccount != static::SETTLE_ACCOUNT_YES + && $settleAccount != static::SETTLE_ACCOUNT_NO + && $settleAccount != static::SETTLE_ACCOUNT_AUTO + ) { + throw new InvalidRequestException('Invalid value for settleAccount.'); + } + + return $this->setParameter('settleAccount', $settleAccount); + } + + public function getSettleAccount() + { + return $this->getParameter('settleAccount'); + } + + public function setTxid($txid) + { + return $this->setParameter('txid', $txid); + } + +} diff --git a/src/Message/ShopServerRefundResponse.php b/src/Message/ShopServerRefundResponse.php new file mode 100644 index 0000000..d5573ee --- /dev/null +++ b/src/Message/ShopServerRefundResponse.php @@ -0,0 +1,11 @@ +createRequest(Message\ShopServerCaptureRequest::class, $parameters); } + /** + * For handling a capture action. + */ + public function refund(array $parameters = array()) + { + return $this->createRequest(Message\ShopServerRefundRequest::class, $parameters); + } + /** * Check a credit card detail for "plausability" and get a card token in response. * This would normally be done client-side, but is available server side too for From d69b07bbc3d2004f3d2509736b2172d0dd06a72c Mon Sep 17 00:00:00 2001 From: Ronald Fiering Date: Tue, 15 Sep 2020 10:24:40 +0200 Subject: [PATCH 2/5] add manage mandate --- .../ShopServerManageMandateRequest.php | 20 +++++++++++++++++++ .../ShopServerManageMandateResponse.php | 11 ++++++++++ src/ShopServerGateway.php | 8 ++++++++ 3 files changed, 39 insertions(+) create mode 100644 src/Message/ShopServerManageMandateRequest.php create mode 100644 src/Message/ShopServerManageMandateResponse.php diff --git a/src/Message/ShopServerManageMandateRequest.php b/src/Message/ShopServerManageMandateRequest.php new file mode 100644 index 0000000..f7607be --- /dev/null +++ b/src/Message/ShopServerManageMandateRequest.php @@ -0,0 +1,20 @@ +response = new ShopServerManageMandateResponse($this, $data); + } +} diff --git a/src/Message/ShopServerManageMandateResponse.php b/src/Message/ShopServerManageMandateResponse.php new file mode 100644 index 0000000..0d1cf03 --- /dev/null +++ b/src/Message/ShopServerManageMandateResponse.php @@ -0,0 +1,11 @@ +createRequest(Message\ShopServerCardCheckRequest::class, $parameters); } + /** + * Helper for managing Sepa Direct Debit Mandate + */ + public function managemandate(array $parameters = array()) + { + return $this->createRequest(Message\ShopServerManageMandateRequest::class, $parameters); + } + /** * For handling a void action. */ From 761ab8bad3185760bb801dc32d0ae4b9b83491c5 Mon Sep 17 00:00:00 2001 From: Ronald Fiering Date: Mon, 21 Sep 2020 14:16:37 +0200 Subject: [PATCH 3/5] add getter and setter for mandate_id --- src/AbstractShopGateway.php | 9 +++++++++ src/ShopClientGateway.php | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/src/AbstractShopGateway.php b/src/AbstractShopGateway.php index dd9cf7f..cbde86e 100644 --- a/src/AbstractShopGateway.php +++ b/src/AbstractShopGateway.php @@ -136,4 +136,13 @@ public function getWalletType() { return $this->getParameter('wallettype'); } + public function getMandateId() + { + return $this->getParameter('mandateId'); + } + + public function setMandateId($id) + { + return $this->setParameter('mandateId', $id); + } } diff --git a/src/ShopClientGateway.php b/src/ShopClientGateway.php index b0b4990..b28caf0 100644 --- a/src/ShopClientGateway.php +++ b/src/ShopClientGateway.php @@ -96,6 +96,14 @@ public function creditCardCheck(array $parameters = array()) return $this->createRequest(Message\ShopClientCardCheckRequest::class, $parameters); } + /** + * Helper for generating the hidden fields in a credit card tokenisation AJAX form. + */ + public function managemandate(array $parameters = array()) + { + return $this->createRequest(Message\ShopServerManageMandateRequest::class, $parameters); + } + /** * Accept an incoming notification (a ServerRequest). * This API supports the notification responses as well as the complete* responses. From 0a7f5bcc697e25690fd04f172e001f31554f8b21 Mon Sep 17 00:00:00 2001 From: Ronald Fiering Date: Mon, 21 Mar 2022 08:37:59 +0100 Subject: [PATCH 4/5] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index de8a835..3c12bed 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "academe/omnipay-payone", + "name": "rf1705/omnipay-payone", "type": "library", "description": "PAYONE gateway driver for the Omnipay PHP payment processing library", "keywords": [ From 49ae95b827aee46282ef9ca2302c1fdf4d2dc395 Mon Sep 17 00:00:00 2001 From: Jason Judge Date: Tue, 23 Aug 2022 18:32:30 +0100 Subject: [PATCH 5/5] Few tweaks to PR#40 Few tweaks to PR#40 to retain some backwards compatibility: * Reset vendor name. * Imports aren't inherited to child classes. * Trailing commas on parameter lists is a PHP 8.x thing only. --- composer.json | 2 +- src/Message/ShopServerAuthorizeRequest.php | 4 ++-- src/Message/ShopServerRefundRequest.php | 3 ++- src/ShopClientGateway.php | 5 +---- src/ShopServerGateway.php | 2 -- 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 3c12bed..de8a835 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "rf1705/omnipay-payone", + "name": "academe/omnipay-payone", "type": "library", "description": "PAYONE gateway driver for the Omnipay PHP payment processing library", "keywords": [ diff --git a/src/Message/ShopServerAuthorizeRequest.php b/src/Message/ShopServerAuthorizeRequest.php index d6ae130..92750ce 100644 --- a/src/Message/ShopServerAuthorizeRequest.php +++ b/src/Message/ShopServerAuthorizeRequest.php @@ -34,7 +34,7 @@ class ShopServerAuthorizeRequest extends AbstractRequest */ protected function getBaseData() { - $data = array( + $data = [ 'mid' => $this->getMerchantId(), 'portalid' => $this->getPortalId(), // Only md5 is used to encode the key for the Server API (no hashing is @@ -47,7 +47,7 @@ protected function getBaseData() 'request' => $this->request_code, 'encoding' => $this->getEncoding(), 'language' => $this->getLanguage(), - ); + ]; return $data; } diff --git a/src/Message/ShopServerRefundRequest.php b/src/Message/ShopServerRefundRequest.php index 6b6174b..cd6cb55 100644 --- a/src/Message/ShopServerRefundRequest.php +++ b/src/Message/ShopServerRefundRequest.php @@ -6,6 +6,8 @@ * PAYONE Shop Capture Request */ +use Omnipay\Common\Exception\InvalidRequestException; + class ShopServerRefundRequest extends ShopServerAuthorizeRequest { /** @@ -152,5 +154,4 @@ public function setTxid($txid) { return $this->setParameter('txid', $txid); } - } diff --git a/src/ShopClientGateway.php b/src/ShopClientGateway.php index b28caf0..72482fb 100644 --- a/src/ShopClientGateway.php +++ b/src/ShopClientGateway.php @@ -7,8 +7,6 @@ * driver for Omnipay */ -use Omnipay\Common\Exception\InvalidRequestException; - class ShopClientGateway extends AbstractShopGateway { /** @@ -20,7 +18,6 @@ class ShopClientGateway extends AbstractShopGateway protected $javascript_url = 'https://secure.pay1.de/client-api/js/v1/payone_hosted_min.js'; protected $endpoint = 'https://secure.pay1.de/client-api/'; - public function getName() { return 'PAYONE Shop Client'; @@ -35,7 +32,7 @@ public function getDefaultParameters() $params['responseType'] = array( static::RETURN_TYPE_JSON, - static::RETURN_TYPE_REDIRECT, + static::RETURN_TYPE_REDIRECT ); return $params; diff --git a/src/ShopServerGateway.php b/src/ShopServerGateway.php index 270b918..384e025 100644 --- a/src/ShopServerGateway.php +++ b/src/ShopServerGateway.php @@ -6,8 +6,6 @@ * ONEPAY Shop (single payments) driver for Omnipay */ -use Omnipay\Common\Exception\InvalidRequestException; - class ShopServerGateway extends AbstractShopGateway { public function getName()