Skip to content

Commit

Permalink
Merge pull request #19 from RobvH/add-reference-sale-support
Browse files Browse the repository at this point in the history
Implement reference purchases
  • Loading branch information
delatbabel authored Nov 10, 2017
2 parents 4a8c1c2 + 7afec74 commit 2348f82
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/Message/PurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,26 @@
* 'testMode' => true, // Or false for live transactions.
* ));
*
* // Next, there are two ways to conduct a sale with Payflow:
* // 1. a reference sale in which an authorization transaction reference is passed
* // 2. a sale in which card data is directly passed
* //
* // #1 should be used any time multiple charges must be committed against an authorization
* // either because parts of an order shipped at different times or because authorization is
* // being used to "tokenize" a card and store it on the gateway (a Paypal prescribed process).
* // Capture can only be called once against an authorization but sale does not have this limitation.
*
* // @see developer.paypal.com/docs/classic/payflow/integration-guide/#submitting-reference-transactions---tokenization
*
* // 1. Reference (tokenized card) Sale example:
* // $reference_id can be the transaction reference from a previous authorization, credit, capture, sale, voice auth,
* // or void.
* $transaction = $gateway->purchase(array(
* 'amount' => '10.00',
* 'transactionReference' => $reference_id,
* ));
*
* // 2. Sale (with card data) example:
* // Create a credit card object
* // This card can be used for testing.
* $card = new CreditCard(array(
Expand Down Expand Up @@ -49,4 +69,25 @@
class PurchaseRequest extends AuthorizeRequest
{
protected $action = 'S';

public function getData()
{
if ($this->parameters->get('transactionReference')) {
return $this->getReferenceSaleData();
}

return parent::getData();
}

public function getReferenceSaleData()
{
$this->validate('transactionReference', 'amount');

$data = $this->getBaseData();
$data['AMT'] = $this->getAmount();
$data['ORIGID'] = $this->getTransactionReference();
$data['TENDER'] = 'C';

return $data;
}
}
15 changes: 15 additions & 0 deletions tests/ProGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ public function testPurchaseSuccess()
$this->assertEquals('A10A6AE7042E', $response->getTransactionReference());
}

public function testReferencePurchaseSuccess()
{
$options = array(
'amount' => '10.00',
'transactionReference' => 'abc123',
);

$this->setMockHttpResponse('PurchaseSuccess.txt');

$response = $this->gateway->purchase($options)->send();

$this->assertTrue($response->isSuccessful());
$this->assertEquals('A10A6AE7042E', $response->getTransactionReference());
}

public function testPurchaseError()
{
$this->setMockHttpResponse('PurchaseFailure.txt');
Expand Down

0 comments on commit 2348f82

Please sign in to comment.