Skip to content

Commit ee4b116

Browse files
committed
adjusted examples
1 parent a2b0740 commit ee4b116

File tree

5 files changed

+140
-20
lines changed

5 files changed

+140
-20
lines changed

examples/callback.php

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,47 @@
11
<?php
22

3+
// include the autoloader
4+
require_once('path/to/vendor/autoload.php');
35
use Exchange\Client\Client;
46
use Exchange\Client\Callback\Result;
57

6-
require_once('../initClientAutoload.php');
7-
8+
// instantiate the "Exchange\Client\Client" with your credentials
89
$client = new Client('username', 'password', 'apiKey', 'sharedSecret');
910

10-
$client->validateCallbackWithGlobals();
11-
$callbackResult = $client->readCallback(file_get_contents('php://input'));
11+
// check if the callback is valid
12+
$valid = $client->validateCallbackWithGlobals();
13+
14+
if($valid){
15+
16+
// read callback data
17+
$callbackResult = $client->readCallback(file_get_contents('php://input'));
18+
19+
} else{
20+
21+
// invalid callback, ignore
22+
die;
23+
24+
}
25+
26+
// handle callback data
27+
$myTransactionId = $callbackResult->getMerchantTransactionId();
28+
$gatewayTransactionId = $callbackResult->getUuid();
1229

13-
$myTransactionId = $callbackResult->getTransactionId();
14-
$gatewayTransactionId = $callbackResult->getReferenceId();
30+
if ($status === Result::RESULT_OK) {
1531

16-
if ($callbackResult->getResult() == Result::RESULT_OK) {
17-
//payment ok
32+
// payment ok
33+
// finishCart();
1834

19-
//finishCart();
35+
} elseif ($status === Result::RESULT_ERROR) {
2036

21-
} elseif ($callbackResult->getResult() == Result::RESULT_ERROR) {
2237
//payment failed, handle errors
23-
$errors = $callbackResult->getErrors();
38+
// $callbackResult->getErrorMessage();
39+
// $callbackResult->getErrorCode();
40+
// $callbackResult->getAdapterMessage();
41+
// $callbackResult->getAdapterCode();
2442

2543
}
2644

45+
// confirm callback with body "OK"
2746
echo "OK";
2847
die;

examples/customerprofile.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
// include the autoloader
4+
require_once('path/to/vendor/autoload.php');
5+
6+
use Exchange\Client\Client;
7+
8+
// instantiate the "Exchange\Client\Client" with your credentials
9+
$client = new Client('username', 'password', 'apiKey', 'sharedSecret');
10+
11+
$result = $client->getCustomerProfileByIdentification('12345');
12+
//$result = $client->getCustomerProfileByProfileGuid('GUID-12345');
13+
14+
// handle result
15+

examples/debit.php

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
<?php
22

3+
// include the autoloader
4+
require_once('path/to/vendor/autoload.php');
35
use Exchange\Client\Client;
46
use Exchange\Client\Data\Customer;
57
use Exchange\Client\Transaction\Debit;
68
use 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')
@@ -17,11 +19,13 @@
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')
@@ -42,24 +46,41 @@
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
4756
if ($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+
}

examples/options.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
// include the autoloader
4+
require_once('path/to/vendor/autoload.php');
5+
6+
use Exchange\Client\Client;
7+
8+
// instantiate the "Exchange\Client\Client" with your credentials
9+
$client = new Client("username", "password", "apiKey", "sharedSecret");
10+
11+
// define parameters if required by the connector
12+
$parameters = ['param1' => 'someValue'];
13+
14+
// retrieve options
15+
$result = $client->getOptions('options_identifier_here', $parameters);
16+
17+
// handle result
18+
if($result->isSuccess()){
19+
// $result->getOptions()
20+
} else{
21+
// $result->getErrorMessage()
22+
}

examples/schedule.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
// include the autoloader
4+
require_once('path/to/vendor/autoload.php');
5+
6+
use Exchange\Client\Client;
7+
use Exchange\Client\Schedule\StartSchedule;
8+
9+
// instantiate the "Exchange\Client\Client" with your credentials
10+
$client = new Client("username", "password", "apiKey", "sharedSecret");
11+
12+
// starting a schedule on an initial register transaction
13+
// to start a schedule make use of StartSchedule
14+
$startSchedule = new StartSchedule();
15+
$startSchedule->setRegistrationUuid('uuid_of_initial_register_here')
16+
->setAmount("9.99")
17+
->setCurrency('EUR')
18+
->setPeriodLength(4)
19+
->setPeriodUnit(StartSchedule::PERIOD_UNIT_MONTH)
20+
->setStartDateTime(new \DateTime());
21+
22+
// send request
23+
$result = $client->startSchedule($startSchedule);
24+
25+
// handle result here
26+
if($result->isSuccess()){
27+
// $result->getScheduleId();
28+
} else{
29+
// $result->getErrorMessage();
30+
// $result->getErrorCode();
31+
}
32+
33+
/*
34+
// other schedule handling examples
35+
$scheduleId = 'schedule_id_comes_here';
36+
37+
$result = $client->showSchedule($scheduleId);
38+
$result = $client->pauseSchedule($scheduleId);
39+
$result = $client->continueSchedule($scheduleId, new \DateTime('2020-10-10 10:00:00 UTC'));
40+
$result = $client->cancelSchedule($scheduleId);
41+
42+
// handle result accordingly
43+
*/

0 commit comments

Comments
 (0)