From ab274221a0eac091e871c162de5e1a928410a872 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E8=89=BE?= <30791785+liu-ai@users.noreply.github.com> Date: Tue, 16 Apr 2019 07:36:26 +0000 Subject: [PATCH 1/3] Update RestAuthorizeRequest.php add invoce_number and custom options to RestPurchaseRequest, users can define themselves. --- src/Message/RestAuthorizeRequest.php | 50 +++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/Message/RestAuthorizeRequest.php b/src/Message/RestAuthorizeRequest.php index 19762f9..0e342cd 100644 --- a/src/Message/RestAuthorizeRequest.php +++ b/src/Message/RestAuthorizeRequest.php @@ -230,7 +230,8 @@ public function getData() 'total' => $this->getAmount(), 'currency' => $this->getCurrency(), ), - 'invoice_number' => $this->getTransactionId() + 'custom' => $this->getCustom(), // custom data + 'invoice_number' => $this->getInvoiceNumber() ) ), 'experience_profile_id' => $this->getExperienceProfileId() @@ -303,6 +304,53 @@ public function getData() return $data; } + + /** + * Get the invoice number to track this payment. + * + * @return string + */ + public function getInvoiceNumber() + { + $id = $this->getParameter('invoiceNumber'); + if(empty($id)){ + return $this->getTransactionId(); + }else{ + return $id; + } + } + + /** + * Set the invoice number to track this payment. + * + * @param string $value + * @return @return $this + */ + public function setInvoiceNumber($value) + { + return $this->setParameter('invoiceNumber', $value); + } + + /** + * Get the free-form field for the client's use. + * + * @return string + */ + public function getCustom() + { + return $this->getParameter('custom'); + } + + /** + * Set the free-form field for the client's use. + * + * @param string $value + * @return $this + */ + public function setCustom($value) + { + return $this->setParameter('custom', $value); + } /** * Get the experience profile id From 3885785c1f016d1eaa1e8bfb64a41edcbcab723b Mon Sep 17 00:00:00 2001 From: liu ai <25417478@qq.com> Date: Tue, 16 Apr 2019 08:17:47 +0000 Subject: [PATCH 2/3] del whitespace found at end of line --- src/Message/RestAuthorizeRequest.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Message/RestAuthorizeRequest.php b/src/Message/RestAuthorizeRequest.php index 0e342cd..a0fc36e 100644 --- a/src/Message/RestAuthorizeRequest.php +++ b/src/Message/RestAuthorizeRequest.php @@ -306,19 +306,19 @@ public function getData() } /** - * Get the invoice number to track this payment. + * Get the invoice number to track this payment. * * @return string */ - public function getInvoiceNumber() - { - $id = $this->getParameter('invoiceNumber'); - if(empty($id)){ - return $this->getTransactionId(); - }else{ - return $id; - } - } + public function getInvoiceNumber() + { + $id = $this->getParameter('invoiceNumber'); + if (empty($id)) { + return $this->getTransactionId(); + } else { + return $id; + } + } /** * Set the invoice number to track this payment. @@ -332,7 +332,7 @@ public function setInvoiceNumber($value) } /** - * Get the free-form field for the client's use. + * Get the free-form field for the client's use. * * @return string */ From 6b6407205b04d4e9c56edeff88a9a1ab7a508fe4 Mon Sep 17 00:00:00 2001 From: liu ai <25417478@qq.com> Date: Wed, 17 Apr 2019 09:17:54 +0000 Subject: [PATCH 3/3] add amount details options to RestPurchaseRequest --- src/Message/RestPurchaseRequest.php | 66 +++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/Message/RestPurchaseRequest.php b/src/Message/RestPurchaseRequest.php index 75b0100..fea44af 100644 --- a/src/Message/RestPurchaseRequest.php +++ b/src/Message/RestPurchaseRequest.php @@ -227,6 +227,72 @@ public function getData() { $data = parent::getData(); $data['intent'] = 'sale'; + $data['transactions'][0]['amount']['details'] = $this->getDetails(); return $data; } + + /* + * Note: For an order authorization or capture, you cannot include the amount details object. + * + */ + public function getDetails() + { + $data = array( + 'subtotal' => $this->getSubtotal(), + 'tax' => $this->getTaxAmount(), + 'shipping' => $this->getShipping(), + 'handling_fee' => $this->getHandlingFee(), + 'shipping_discount' => $this->getShippingDiscount(), + 'insurance' => $this->getInsurance() + ); + $data = array_filter($data); + return $data; + } + + private function getSubtotal() + { + $subtotal = 0; + $items = $this->getItems(); + if ($items) { + foreach ($items as $n => $item) { + $subtotal += $item->getPrice(); + } + return $this->formatCurrency($subtotal); + } else { + return $this->getAmount(); + } + } + + public function getShipping() + { + return ($this->getParameter('shipping'))?$this->formatCurrency($this->getParameter('shipping')):null; + } + public function setShipping($value) + { + return $this->setParameter('shipping', $value !== null ? (string) $value : null); + } + public function getHandlingFee() + { + return ($this->getParameter('handlingFee'))?$this->formatCurrency($this->getParameter('handlingFee')):null; + } + public function setHandlingFee($value) + { + return $this->setParameter('handlingFee', $value !== null ? (string) $value : null); + } + public function getShippingDiscount() + { + return ($this->getParameter('shippingDiscount'))?$this->formatCurrency($this->getParameter('shippingDiscount')):null; + } + public function setShippingDiscount($value) + { + return $this->setParameter('shippingDiscount', $value !== null ? (string) $value : null); + } + public function getInsurance() + { + return ($this->getParameter('insurance'))?$this->formatCurrency($this->getParameter('insurance')):null; + } + public function setInsurance($value) + { + return $this->setParameter('insurance', $value !== null ? (string) $value : null); + } }