-
Notifications
You must be signed in to change notification settings - Fork 27
/
TransactionApiExample.php
66 lines (57 loc) · 1.79 KB
/
TransactionApiExample.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
57
58
59
60
61
62
63
64
65
66
<?php
namespace Tpay\Example;
use Tpay\OriginApi\TransactionApi;
use Tpay\OriginApi\Utilities\TException;
include_once 'config.php';
include_once 'loader.php';
final class TransactionApiExample extends TransactionApi
{
private $trId;
public function __construct()
{
$this->merchantSecret = 'demo';
$this->merchantId = 1010;
$this->trApiKey = '75f86137a6635df826e3efe2e66f7c9a946fdde1';
$this->trApiPass = 'p@$$w0rd#@!';
parent::__construct();
}
public function getTransaction()
{
/**
* Get info about transaction
*/
$transactionId = $this->trId;
try {
$transaction = $this->setTransactionID($transactionId)->get();
print_r($transaction);
} catch (TException $e) {
var_dump($e);
}
}
public function createTransaction()
{
/**
* Create new transaction
*/
$config = [
'amount' => 999.99,
'description' => 'Transaction description',
'crc' => '100020003000',
'result_url' => 'http://example.pl/examples/TransactionApiExample.php?transaction_confirmation',
'result_email' => 'shop@example.com',
'return_url' => 'http://example.pl/examples/TransactionApiExample.php',
'email' => 'customer@example.com',
'name' => 'John Doe',
'group' => isset($_POST['group']) ? (int) $_POST['group'] : 150,
'accept_tos' => 1,
];
try {
$res = $this->create($config);
$this->trUrl = $res['url'];
echo '<a href='.$this->trUrl.'>go to payment</a>';
} catch (TException $e) {
var_dump($e);
}
}
}
(new TransactionApiExample())->createTransaction();