11<?php
22
3+ // include the autoloader
4+ require_once ('path/to/vendor/autoload.php ' );
35use Exchange \Client \Client ;
46use Exchange \Client \Data \Customer ;
57use Exchange \Client \Transaction \Debit ;
68use Exchange \Client \Transaction \Result ;
79
8- require_once ('../initClientAutoload.php ' );
9-
10- $ client = new Client ('username ' , 'password ' , 'apiKey ' , 'sharedSecret ' );
10+ // instantiate the "Exchange\Client\Client" with your credentials
11+ $ client = new Client ("username " , "password " , "apiKey " , "sharedSecret " );
1112
13+ // define relevant objects
1214$ customer = new Customer ();
1315$ customer
1416 ->setFirstName ('John ' )
1719 ->setIpAddress ('123.123.123.123 ' );
1820//add further customer details if necessary
1921
20- // define your transaction ID: e.g. 'myId-'.date('Y-m-d').'-'.uniqid()
21- $ merchantTransactionId = 'your_transaction_id ' ; // must be unique
22+ // define your transaction ID
23+ // must be unique! e.g.
24+ $ merchantTransactionId = $ merchantTransactionId = uniqid ('myId ' , true ) . '- ' . date ('YmdHis ' );
2225
26+ // define transaction relevant object
2327$ debit = new Debit ();
24- $ debit ->setTransactionId ($ merchantTransactionId )
28+ $ debit ->setMerchantTransactionId ($ merchantTransactionId )
2529 ->setAmount (9.99 )
2630 ->setCurrency ('EUR ' )
2731 ->setCallbackUrl ('https://myhost.com/path/to/my/callbackHandler ' )
4246
4347$ result = $ client ->debit ($ debit );
4448
45- $ gatewayReferenceId = $ result ->getReferenceId (); //store it in your database
49+ // handle the result
50+ if ($ result ->isSuccess ()) {
51+
52+ // store the uuid you receive from the gateway for future references
53+ $ gatewayReferenceId = $ result ->getUuid ();
4654
55+ // handle result based on it's returnType
4756if ($ result ->getReturnType () == Result::RETURN_TYPE_ERROR ) {
4857 //error handling
4958 $ errors = $ result ->getErrors ();
59+ // handle the error
5060 //cancelCart();
5161
5262} elseif ($ result ->getReturnType () == Result::RETURN_TYPE_REDIRECT ) {
5363 //redirect the user
5464 header ('Location: ' .$ result ->getRedirectUrl ());
55- die;
65+
5666} elseif ($ result ->getReturnType () == Result::RETURN_TYPE_PENDING ) {
5767 //payment is pending, wait for callback to complete
5868
69+ // handle pending
5970 //setCartToPending();
6071
6172} elseif ($ result ->getReturnType () == Result::RETURN_TYPE_FINISHED ) {
6273 //payment is finished, update your cart/payment transaction
6374
6475 //finishCart();
65- }
76+ }
77+
78+ } else {
79+
80+ // handle error
81+ // $result->getErrorMessage()
82+ // $result->getErrorCode()
83+ // $result->getAdapterMessage()
84+ // $result->getAdapterCode()
85+
86+ }
0 commit comments