-
Notifications
You must be signed in to change notification settings - Fork 0
/
Driver.php
51 lines (44 loc) · 1.5 KB
/
Driver.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* This is an example of how you would use the objects
*/
$gatewayName = 'AuthorizeNet';
$credentials = new stdClass();
$credentials->login = 'login';
$credentials->key = 'key';
/**
* Here you would have some logic to determine which gateway to use. We are using a factory class to accomplish this.
*/
/** @var \gateways\GatewayInterface|null $gateway */
$gateway = null;
switch ($gatewayName) {
case 'AuthorizeNet':
$gateway = new \gateways\AuthorizeNet($credentials);
break;
case 'FirstData':
$gateway = new \gateways\FirstData($credentials);
break;
default:
throw new Exception('bad gateway name');
}
/**
* This array would be an associative array with a standard set of keys for your system that don't change.
*/
$paymentDetails = [];
/**
* If you created purchase/refund/etc. methods in your gateway classes then you can call it like this.
*/
$response = $gateway->purchase($paymentDetails);
/**
* If you did not create those methods then you can call the purchase like this. Obviously the one above is cleaner here
* but it makes the classes more complex so that is personal choice. In our system the one above works better.
*/
$response = $gateway->gateway->purchase($gateway->getPurchaseData($paymentDetails))->send();
/**
* Get the transaction ID and code like so
*/
$transactionId = $gateway->getTransactionId($response);
$transactionCode = $gateway->getTransactionResultCode($response);
/**
* Refunds are basically run the same as the purchase
*/