Skip to content

Commit e9d755e

Browse files
Add support for making a payment when creating a token for Shared & Transparent methods
1 parent 24731f9 commit e9d755e

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

Diff for: src/Message/RapidResponse.php

+5
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ public function getCardReference()
5959
if (isset($this->data['Customer']['TokenCustomerID'])) {
6060
return $this->data['Customer']['TokenCustomerID'];
6161
}
62+
if (isset($this->data['TokenCustomerID'])) {
63+
// This format appears when creating a card and making a concurrent
64+
// payment using Shared or Transparent redirect methods.
65+
return $this->data['TokenCustomerID'];
66+
}
6267

6368
return null;
6469
}

Diff for: src/Message/RapidSharedCreateCardRequest.php

+31-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,30 @@
1414
*/
1515
class RapidSharedCreateCardRequest extends RapidSharedPurchaseRequest
1616
{
17+
protected $action;
18+
19+
/**
20+
* @return string|NULL
21+
*/
22+
public function getAction()
23+
{
24+
return $this->action;
25+
}
26+
27+
/**
28+
* @param string $action
29+
*/
30+
public function setAction($action)
31+
{
32+
$this->action = $action;
33+
}
34+
1735
public function getData()
1836
{
1937
$this->validate('returnUrl');
2038

2139
$data = $this->getBaseData();
22-
$data['Method'] = 'CreateTokenCustomer';
40+
2341
$data['TransactionType'] = 'Purchase';
2442
$data['RedirectUrl'] = $this->getReturnUrl();
2543

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

3452
$data['Payment'] = array();
35-
$data['Payment']['TotalAmount'] = 0;
53+
54+
if ($this->getAction() === 'Purchase') {
55+
$data['Payment']['TotalAmount'] = (int) $this->getAmountInteger();
56+
$data['Payment']['InvoiceNumber'] = $this->getTransactionId();
57+
$data['Payment']['InvoiceDescription'] = $this->getDescription();
58+
$data['Payment']['CurrencyCode'] = $this->getCurrency();
59+
$data['Payment']['InvoiceReference'] = $this->getInvoiceReference();
60+
$data['Method'] = 'TokenPayment';
61+
} else {
62+
$data['Method'] = 'CreateTokenCustomer';
63+
$data['Payment']['TotalAmount'] = 0;
64+
}
3665

3766
return $data;
3867
}

0 commit comments

Comments
 (0)