Skip to content

Commit 71eeca0

Browse files
author
iampersistent
committed
update option in token to match existing options
1 parent fa2d068 commit 71eeca0

File tree

5 files changed

+67
-24
lines changed

5 files changed

+67
-24
lines changed

src/Message/AbstractRequest.php

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,16 +259,6 @@ public function setPurchaseOrderNumber($value)
259259
return $this->setParameter('purchaseOrderNumber', $value);
260260
}
261261

262-
public function getOptions()
263-
{
264-
return $this->getParameter('options');
265-
}
266-
267-
public function setOptions($value)
268-
{
269-
return $this->setParameter('options', $value);
270-
}
271-
272262
public function getTaxAmount()
273263
{
274264
return $this->getParameter('taxAmount');
@@ -309,6 +299,16 @@ public function setPaymentMethodNonce($value)
309299
return $this->setToken($value);
310300
}
311301

302+
public function getFailOnDuplicatePaymentMethod()
303+
{
304+
return $this->getParameter('failOnDuplicatePaymentMethod');
305+
}
306+
307+
public function setFailOnDuplicatePaymentMethod($value)
308+
{
309+
return $this->setParameter('failOnDuplicatePaymentMethod', (bool) $value);
310+
}
311+
312312
/**
313313
* @return array
314314
*/
@@ -346,6 +346,32 @@ public function getCardData()
346346
);
347347
}
348348

349+
/**
350+
* @return array
351+
*/
352+
public function getOptionData()
353+
{
354+
$data = array(
355+
'addBillingAddressToPaymentMethod' => $this->getAddBillingAddressToPaymentMethod(),
356+
'failOnDuplicatePaymentMethod' => $this->getFailOnDuplicatePaymentMethod(),
357+
'holdInEscrow' => $this->getHoldInEscrow(),
358+
'storeInVault' => $this->getStoreInVault(),
359+
'storeInVaultOnSuccess' => $this->getStoreInVaultOnSuccess(),
360+
'storeShippingAddressInVault' => $this->getStoreShippingAddressInVault(),
361+
);
362+
363+
// Remove null values
364+
$data = array_filter($data, function($value){
365+
return ! is_null($value);
366+
});
367+
368+
if (empty($data)) {
369+
return $data;
370+
} else {
371+
return array('options' => $data);
372+
}
373+
}
374+
349375
protected function createResponse($data)
350376
{
351377
return $this->response = new Response($this, $data);

src/Message/AuthorizeRequest.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@ public function getData()
2525
'deviceData' => $this->getDeviceData(),
2626
'deviceSessionId' => $this->getDeviceSessionId(),
2727
'merchantAccountId' => $this->getMerchantAccountId(),
28-
'options' => [
29-
'addBillingAddressToPaymentMethod' => $this->getAddBillingAddressToPaymentMethod(),
30-
'holdInEscrow' => $this->getHoldInEscrow(),
31-
'storeInVault' => $this->getStoreInVault(),
32-
'storeInVaultOnSuccess' => $this->getStoreInVaultOnSuccess(),
33-
'storeShippingAddressInVault' => $this->getStoreShippingAddressInVault(),
34-
'submitForSettlement' => false,
35-
],
3628
'orderId' => $this->getTransactionId(),
3729
'purchaseOrderNumber' => $this->getPurchaseOrderNumber(),
3830
'recurring' => $this->getRecurring(),
@@ -55,7 +47,9 @@ public function getData()
5547
return ! is_null($value);
5648
});
5749

50+
$data += $this->getOptionData();
5851
$data += $this->getCardData();
52+
$data['options']['submitForSettlement'] = false;
5953

6054
return $data;
6155
}

src/Message/ClientTokenRequest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ public function getData()
1616
if ($customerId = $this->getCustomerId()) {
1717
$data['customerId'] = $customerId;
1818
}
19-
if ($options = $this->getOptions()) {
20-
$data['options'] = $options;
21-
}
19+
$data += $this->getOptionData();
2220

2321
return $data;
2422
}

tests/Message/AbstractRequestTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,25 @@ public function testCardData()
126126
$this->assertSame($card['shippingCountry'], $data['shipping']['countryName']);
127127

128128
}
129+
130+
public function testOptionData()
131+
{
132+
$options = [
133+
'addBillingAddressToPaymentMethod' => false,
134+
'failOnDuplicatePaymentMethod' => true,
135+
'holdInEscrow' => false,
136+
'storeInVault' => true,
137+
'storeInVaultOnSuccess' => false,
138+
'storeShippingAddressInVault' => true,
139+
];
140+
$this->request->initialize($options);
141+
$data = $this->request->getOptionData();
142+
143+
$this->assertSame($options['addBillingAddressToPaymentMethod'], $data['options']['addBillingAddressToPaymentMethod']);
144+
$this->assertSame($options['failOnDuplicatePaymentMethod'], $data['options']['failOnDuplicatePaymentMethod']);
145+
$this->assertSame($options['holdInEscrow'], $data['options']['holdInEscrow']);
146+
$this->assertSame($options['storeInVault'], $data['options']['storeInVault']);
147+
$this->assertSame($options['storeInVaultOnSuccess'], $data['options']['storeInVaultOnSuccess']);
148+
$this->assertSame($options['storeShippingAddressInVault'], $data['options']['storeShippingAddressInVault']);
149+
}
129150
}

tests/Message/ClientTokenRequestTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,19 @@ public function testGetData()
2727

2828
public function testGetDataWithCustomer()
2929
{
30-
$data = array(
30+
$setData = array(
31+
'customerId' => '4815162342',
32+
'failOnDuplicatePaymentMethod' => true,
33+
);
34+
$expectedData = array(
3135
'customerId' => '4815162342',
3236
'options' => array(
3337
'failOnDuplicatePaymentMethod' => true,
3438
),
3539
);
36-
$this->request->initialize($data);
40+
$this->request->initialize($setData);
3741
$this->assertSame('4815162342', $this->request->getCustomerId());
38-
$this->assertSame($data, $this->request->getData());
42+
$this->assertSame($expectedData, $this->request->getData());
3943
}
4044

4145
}

0 commit comments

Comments
 (0)