Skip to content

Commit 3ed4d4d

Browse files
Add authorize handling for using a stored billing agreement
1 parent b2a5e0d commit 3ed4d4d

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

src/Message/RestAuthorizeRequest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,20 @@ public function getData()
253253
$data['transactions'][0]['item_list']["items"] = $itemList;
254254
}
255255

256-
if ($this->getCardReference()) {
256+
if ($this->getCardReference() && substr($this->getCardReference(), 0, 2) === 'B-') {
257+
// Card references can be for a billing agreement (format B-....) or a stored card format CARD-...
258+
// here billing agreement
259+
// https://developer.paypal.com/docs/limited-release/reference-transactions/#use-a-reference-transaction-to-make-a-payment
260+
$this->validate('amount');
261+
$data['payer']['funding_instruments'][] = array(
262+
'billing' => array(
263+
'billing_agreement_id' => $this->getCardReference(),
264+
),
265+
);
266+
$data['payer']['payment_method'] = 'paypal';
267+
} elseif ($this->getCardReference()) {
268+
// stored card
269+
//https://developer.paypal.com/docs/integration/direct/vault/#pay-with-vaulted-card
257270
$this->validate('amount');
258271

259272
$data['payer']['funding_instruments'][] = array(

src/Message/RestCompleteCreateCardRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace Omnipay\PayPal\Message;
77

88
/**
9-
* PayPal REST Complete Subscription Request
9+
* PayPal REST Complete Create Card Request
1010
*
1111
* Use this call to create a billing agreement after the buyer approves it.
1212
*

src/Message/RestResponse.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,26 @@ public function getCode()
7272

7373
/**
7474
* Get a string that will represent the stored card in future requests.
75+
*
76+
* If they have authorised the payment through submitting a card through Omnipay
77+
* this will be a reference to the card in the vault. If they have authorised the payment
78+
* through paypal this will be a reference to an approved billing agreement.
7579
*/
7680
public function getCardReference()
7781
{
82+
if ($this->isPaypalApproval()) {
83+
return $this->data['payer']['funding_instruments'][0]['billing']['billing_agreement_id'];
84+
}
7885
if (isset($this->data['id'])) {
7986
return $this->data['id'];
8087
}
8188
}
89+
90+
public function isPaypalApproval()
91+
{
92+
if (!isset($this->data['payer']['payment_method'])) {
93+
return false;
94+
}
95+
return ($this->data['payer']['payment_method'] === 'paypal');
96+
}
8297
}

0 commit comments

Comments
 (0)