-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathrefund.php
56 lines (42 loc) · 1.86 KB
/
refund.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
52
53
54
55
56
<?php
require_once __DIR__ . '/../BeGateway.php';
require_once __DIR__ . '/test_shop_data.php';
BeGateway\Logger::getInstance()->setLogLevel(BeGateway\Logger::DEBUG);
$transaction = new BeGateway\PaymentOperation;
$amount = rand(1, 100);
$transaction->money->setAmount($amount);
$transaction->money->setCurrency('EUR');
$transaction->setDescription('test');
$transaction->setTrackingId('my_custom_variable');
$transaction->setTestMode(true);
$transaction->card->setCardNumber('4200000000000000');
$transaction->card->setCardHolder('JOHN DOE');
$transaction->card->setCardExpMonth('01');
$transaction->card->setCardExpYear(2030);
$transaction->card->setCardCvc('123');
$transaction->customer->setFirstName('John');
$transaction->customer->setLastName('Doe');
$transaction->customer->setCountry('LV');
$transaction->customer->setAddress('Demo str 12');
$transaction->customer->setCity('Riga');
$transaction->customer->setZip('LV-1082');
$transaction->customer->setIp('127.0.0.1');
$transaction->customer->setEmail('[email protected]');
$response = $transaction->submit();
echo 'Transaction message: ' . $response->getMessage() . PHP_EOL;
echo 'Transaction status: ' . $response->getStatus() . PHP_EOL;
if ($response->isSuccess()) {
echo 'Transaction UID: ' . $response->getUid() . PHP_EOL;
echo 'Trying to Refund transaction ' . $response->getUid() . PHP_EOL;
$refund = new BeGateway\RefundOperation;
$refund->setParentUid($response->getUid());
$refund->money->setAmount($transaction->money->getAmount());
$refund->setReason('customer request');
$refund_response = $refund->submit();
if ($refund_response->isSuccess()) {
echo 'Refund successfuly. Refund transaction UID ' . $refund_response->getUid() . PHP_EOL;
} else {
echo 'Problem to refund' . PHP_EOL;
echo 'Refund message: ' . $refund_response->getMessage() . PHP_EOL;
}
}