Skip to content

Commit

Permalink
Add support for making a payment when creating a token for Shared & T…
Browse files Browse the repository at this point in the history
…ransparent methods
  • Loading branch information
eileenmcnaughton committed Sep 25, 2017
1 parent 24731f9 commit e9d755e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/Message/RapidResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public function getCardReference()
if (isset($this->data['Customer']['TokenCustomerID'])) {
return $this->data['Customer']['TokenCustomerID'];
}
if (isset($this->data['TokenCustomerID'])) {
// This format appears when creating a card and making a concurrent
// payment using Shared or Transparent redirect methods.
return $this->data['TokenCustomerID'];
}

return null;
}
Expand Down
33 changes: 31 additions & 2 deletions src/Message/RapidSharedCreateCardRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,30 @@
*/
class RapidSharedCreateCardRequest extends RapidSharedPurchaseRequest
{
protected $action;

/**
* @return string|NULL
*/
public function getAction()
{
return $this->action;
}

/**
* @param string $action
*/
public function setAction($action)
{
$this->action = $action;
}

public function getData()
{
$this->validate('returnUrl');

$data = $this->getBaseData();
$data['Method'] = 'CreateTokenCustomer';

$data['TransactionType'] = 'Purchase';
$data['RedirectUrl'] = $this->getReturnUrl();

Expand All @@ -32,7 +50,18 @@ public function getData()
$data['CustomView'] = $this->getCustomView();

$data['Payment'] = array();
$data['Payment']['TotalAmount'] = 0;

if ($this->getAction() === 'Purchase') {
$data['Payment']['TotalAmount'] = (int) $this->getAmountInteger();
$data['Payment']['InvoiceNumber'] = $this->getTransactionId();
$data['Payment']['InvoiceDescription'] = $this->getDescription();
$data['Payment']['CurrencyCode'] = $this->getCurrency();
$data['Payment']['InvoiceReference'] = $this->getInvoiceReference();
$data['Method'] = 'TokenPayment';
} else {
$data['Method'] = 'CreateTokenCustomer';
$data['Payment']['TotalAmount'] = 0;
}

return $data;
}
Expand Down

0 comments on commit e9d755e

Please sign in to comment.