diff --git a/src/Message/RestAuthorizeRequest.php b/src/Message/RestAuthorizeRequest.php index 19762f9..a0fc36e 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 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); + } }