Skip to content

Commit 2348f82

Browse files
authored
Merge pull request #19 from RobvH/add-reference-sale-support
Implement reference purchases
2 parents 4a8c1c2 + 7afec74 commit 2348f82

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/Message/PurchaseRequest.php

+41
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,26 @@
2121
* 'testMode' => true, // Or false for live transactions.
2222
* ));
2323
*
24+
* // Next, there are two ways to conduct a sale with Payflow:
25+
* // 1. a reference sale in which an authorization transaction reference is passed
26+
* // 2. a sale in which card data is directly passed
27+
* //
28+
* // #1 should be used any time multiple charges must be committed against an authorization
29+
* // either because parts of an order shipped at different times or because authorization is
30+
* // being used to "tokenize" a card and store it on the gateway (a Paypal prescribed process).
31+
* // Capture can only be called once against an authorization but sale does not have this limitation.
32+
*
33+
* // @see developer.paypal.com/docs/classic/payflow/integration-guide/#submitting-reference-transactions---tokenization
34+
*
35+
* // 1. Reference (tokenized card) Sale example:
36+
* // $reference_id can be the transaction reference from a previous authorization, credit, capture, sale, voice auth,
37+
* // or void.
38+
* $transaction = $gateway->purchase(array(
39+
* 'amount' => '10.00',
40+
* 'transactionReference' => $reference_id,
41+
* ));
42+
*
43+
* // 2. Sale (with card data) example:
2444
* // Create a credit card object
2545
* // This card can be used for testing.
2646
* $card = new CreditCard(array(
@@ -49,4 +69,25 @@
4969
class PurchaseRequest extends AuthorizeRequest
5070
{
5171
protected $action = 'S';
72+
73+
public function getData()
74+
{
75+
if ($this->parameters->get('transactionReference')) {
76+
return $this->getReferenceSaleData();
77+
}
78+
79+
return parent::getData();
80+
}
81+
82+
public function getReferenceSaleData()
83+
{
84+
$this->validate('transactionReference', 'amount');
85+
86+
$data = $this->getBaseData();
87+
$data['AMT'] = $this->getAmount();
88+
$data['ORIGID'] = $this->getTransactionReference();
89+
$data['TENDER'] = 'C';
90+
91+
return $data;
92+
}
5293
}

tests/ProGatewayTest.php

+15
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,21 @@ public function testPurchaseSuccess()
7171
$this->assertEquals('A10A6AE7042E', $response->getTransactionReference());
7272
}
7373

74+
public function testReferencePurchaseSuccess()
75+
{
76+
$options = array(
77+
'amount' => '10.00',
78+
'transactionReference' => 'abc123',
79+
);
80+
81+
$this->setMockHttpResponse('PurchaseSuccess.txt');
82+
83+
$response = $this->gateway->purchase($options)->send();
84+
85+
$this->assertTrue($response->isSuccessful());
86+
$this->assertEquals('A10A6AE7042E', $response->getTransactionReference());
87+
}
88+
7489
public function testPurchaseError()
7590
{
7691
$this->setMockHttpResponse('PurchaseFailure.txt');

0 commit comments

Comments
 (0)