forked from tpay-com/tpay-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTransactionApiExample.php
76 lines (60 loc) · 1.89 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
67
68
69
70
71
72
73
74
75
76
<?php
/*
* Created by tpay.com
*/
namespace tpayLibs\examples;
use tpayLibs\src\_class_tpay\Utilities\TException;
use tpayLibs\src\_class_tpay\TransactionApi;
include_once 'config.php';
include_once 'loader.php';
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 = array(
'amount' => 999.99,
'description' => 'Transaction description',
'crc' => '100020003000',
'result_url' => 'http://example.pl/examples/TransactionApiExample.php?transaction_confirmation',
'result_email' => '[email protected]',
'return_url' => 'http://example.pl/examples/TransactionApiExample.php',
'email' => '[email protected]',
'name' => 'John Doe',
'group' => isset($_POST['group']) ? (int)$_POST['group'] : 150,
'accept_tos' => 1,
);
try {
$res = $this->create($config);
$this->trId = $res['title'];
echo '<a href="https://secure.tpay.com/?gtitle=' . $this->trId . '">go to payment</a>';
} catch (TException $e) {
var_dump($e);
}
}
}
(new TransactionApiExample())->createTransaction();