Skip to content

add invoce_number and custom options to RestPurchaseRequest #230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion src/Message/RestAuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
66 changes: 66 additions & 0 deletions src/Message/RestPurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}