Skip to content

Commit 15b4fb4

Browse files
committed
Merge pull request #23 from musement/master
add 'cardholderName' to AuthorizeRequest and CreatePaymentMethodRequest
2 parents e4b4027 + 5369d97 commit 15b4fb4

File tree

3 files changed

+84
-10
lines changed

3 files changed

+84
-10
lines changed

src/Message/AuthorizeRequest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ public function getData()
4848
return ! is_null($value);
4949
});
5050

51+
if ($this->getCardholderName()) {
52+
$data['creditCard'] = array(
53+
'cardholderName' => $this->getCardholderName(),
54+
);
55+
}
56+
5157
$data += $this->getOptionData();
5258
$data += $this->getCardData();
5359
$data['options']['submitForSettlement'] = false;
@@ -67,4 +73,24 @@ public function sendData($data)
6773

6874
return $this->createResponse($response);
6975
}
76+
77+
/**
78+
* [optional] The cardholder name associated with the credit card. 175 character maximum.
79+
* Required for iOS integration because its missing in "tokenizeCard" function there.
80+
* See: https://developers.braintreepayments.com/reference/request/transaction/sale/php#credit_card.cardholder_name
81+
*
82+
* @param $value
83+
* @return mixed
84+
*/
85+
public function setCardholderName($value)
86+
{
87+
$cardholderName = trim($value);
88+
$cardholderName = strlen($cardholderName)>0 ? $cardholderName : null;
89+
return $this->setParameter('cardholderName', $cardholderName);
90+
}
91+
92+
public function getCardholderName()
93+
{
94+
return $this->getParameter('cardholderName');
95+
}
7096
}

src/Message/CreatePaymentMethodRequest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public function getData()
1717
'customerId' => $this->getCustomerId(),
1818
'paymentMethodNonce' => $this->getToken(),
1919
);
20+
if ($cardholderName = $this->getCardholderName()) {
21+
$data['cardholderName'] = $cardholderName;
22+
}
2023
$data += $this->getOptionData();
2124

2225
return $data;
@@ -34,4 +37,24 @@ public function sendData($data)
3437

3538
return $this->createResponse($response);
3639
}
40+
41+
/**
42+
* [optional] The cardholder name associated with the credit card. 175 character maximum.
43+
* Required for iOS integration because its missing in "tokenizeCard" function there.
44+
* See: https://developers.braintreepayments.com/reference/request/payment-method/create/php#cardholder_name
45+
*
46+
* @param $value
47+
* @return mixed
48+
*/
49+
public function setCardholderName($value)
50+
{
51+
$cardholderName = trim($value);
52+
$cardholderName = strlen($cardholderName)>0 ? $cardholderName : null;
53+
return $this->setParameter('cardholderName', $cardholderName);
54+
}
55+
56+
public function getCardholderName()
57+
{
58+
return $this->getParameter('cardholderName');
59+
}
3760
}

tests/Message/CreatePaymentMethodRequestTest.php

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,59 @@
66

77
class CreatePaymentMethodRequestTest extends TestCase
88
{
9-
/**
10-
* @var CreatePaymentMethodRequest
11-
*/
12-
private $request;
13-
14-
public function setUp()
9+
public function testGetData()
1510
{
16-
$this->request = new CreatePaymentMethodRequest($this->getHttpClient(), $this->getHttpRequest(), \Braintree_Configuration::gateway());
17-
$this->request->initialize(
11+
$request = $this->createPaymentMethodRequest();
12+
$request->initialize(
1813
array(
1914
'customerId' => '4815162342',
2015
'token' => 'abc123',
2116
'verifyCard' => true,
2217
'verificationMerchantAccountId' => '123581321',
2318
)
2419
);
20+
21+
$expectedData = array(
22+
'customerId' => '4815162342',
23+
'paymentMethodNonce' => 'abc123',
24+
'options' => array(
25+
'verifyCard' => true,
26+
'verificationMerchantAccountId' => '123581321',
27+
)
28+
);
29+
$this->assertSame($expectedData, $request->getData());
2530
}
2631

27-
public function testGetData()
32+
public function testGetDataWithCardholderName()
2833
{
34+
$request = $this->createPaymentMethodRequest();
35+
$request->initialize(
36+
array(
37+
'customerId' => '4815162342',
38+
'token' => 'abc123',
39+
'cardholderName' => 'John Yolo',
40+
'verifyCard' => true,
41+
'verificationMerchantAccountId' => '123581321',
42+
)
43+
);
44+
2945
$expectedData = array(
3046
'customerId' => '4815162342',
3147
'paymentMethodNonce' => 'abc123',
48+
'cardholderName' => 'John Yolo',
3249
'options' => array(
3350
'verifyCard' => true,
3451
'verificationMerchantAccountId' => '123581321',
3552
)
3653
);
37-
$this->assertSame($expectedData, $this->request->getData());
54+
$this->assertSame($expectedData, $request->getData());
55+
}
56+
57+
/**
58+
* @return CreatePaymentMethodRequest
59+
*/
60+
private function createPaymentMethodRequest()
61+
{
62+
return new CreatePaymentMethodRequest($this->getHttpClient(), $this->getHttpRequest(), \Braintree_Configuration::gateway());
3863
}
3964
}

0 commit comments

Comments
 (0)