forked from tcmug/fpiapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.php
206 lines (164 loc) · 5.18 KB
/
test.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?php
/**
* Test and demo case
*/
session_start();
require __DIR__ . '/vendor/autoload.php';
//namespace FpiApi\Gateway;
use FpiApi\Transaction;
use FpiApi\Factory;
//use FpiApi\FpiapiException;
if (isset($_GET['gt']))
$gatewayName = $_GET['gt'];
else
$gatewayName = isset($_SESSION['gateway']) ? $_SESSION['gateway'] : '';
$_SESSION['gateway'] = $gatewayName;
$banks = array(
"danskebank" => array(
"publicKey" => "000000000000",
"privateKey" => "jumCLB4T2ceZWGJ9ztjuhn5FaeZnTm5HpfDXWU2APRqfDcsrBs8mqkFARzm7uXKd",
"merchantId" => "00123456800",
"contractNumber" => "123456",
"version" => 4,
),
"aktia" => array(
"version" => "010", // Always this
"publicKey" => "1111111111111",
"privateKey" => "1234567890123456789012345678901234567890123456789012345678901234",
"accountName" => "Testiverkkokauppa"
),
"sp" => array(
"version" => "003", // or 002
"publicKey" => "0000000000",
"privateKey" => "11111111111111111111"
),
"pop" => array(
"version" => "003", // or 002
"publicKey" => "0000000000",
"privateKey" => "11111111111111111111",
"accountNumber" => "448710-126", // not required
"accountName" => 'testitili' // not required
),
"osuuspankki" => array(
"publicKey" => "Esittelymyyja",
"privateKey" => "Esittelykauppiaansalainentunnus"
),
"handelsbanken" => array(
"publicKey" => "0000000000",
"privateKey" => "11111111111111111111"
),
"nordea" => array(
"publicKey" => "12345678",
"privateKey" => "LEHTI",
"accountNumber" => "123",
"accountName" => "Testailija",
),
"Spankki" => array(
"publicKey" => "SPANKKIESHOPID",
"privateKey" => "SPANKKI",
"accountNumber" => "FI4139390001002369",
"accountName" => "Testailija"
),
"alandsbanken" => array(
"publicKey" => "AABESHOPID",
"privateKey" => "PAPEGOJA",
"accountNumber" => "660100-01130855",
"accountName" => "Testailija"
),
"tapiola" => array(
"publicKey" => "TAPESHOPID",
"privateKey" => "PAPUKAIJA",
"accountNumber" => "363630-01652643",
"accountName" => "Testailija"
),
"luottokunta" => array(
"publicKey" => "7778883",
"privateKey" => "KTLDJ546GDS"
)
);
foreach ($banks as $bankName => $o) {
?><a href="?gt=<?php print $bankName?>"><?php print $bankName; ?></a> <?php
}
?><br/><br/><?php
if (!$gatewayName) {
exit;
}
$t = new Transaction();
$t->setSum("250,14");
$t->setUid("1");
$t->setDueDate(date("Y-m-d", strtotime("+5 days")));
$t->setReferenceBaseNumber(10000);
$t->setReferencePaddingLength(0);
$gateway = Factory::getGateway($gatewayName);
$host = 'http://' . $_SERVER['HTTP_HOST'] . '/test.php';
// Aktia uses a different URL for testing.
if ($gatewayName == 'aktia') {
$gateway->setPaymentUrl('https://auth.aktia.fi/vmtest');
}
$gateway->setCurrency("EUR");
$gateway->setConfiguration($banks[$gatewayName]);
$gateway->setTransaction($t);
$gateway->setReturnUrl($host . "?ok=1");
$gateway->setErrorUrl($host . "?error=1");
$gateway->setLanguage("fi");
try {
// if ($qr = $gateway->getQueryResult()) {
// var_dump($qr);
// }
if ($gateway->isPaymentCompleted()) {
?><h1>Payment completed</h1><?php
} else {
?><h1>Payment not completed</h1><?php
}
} catch (FpiapiException $e) {
?><h1><?php print $e->getMessage(); ?></h1><?php
}
?>
<h2><?php echo $gateway->getName();?></h2> <img src='<?php print $gateway->getImageUrl();?>'>
<pre>
<?php print_r($_REQUEST); ?>
</pre>
<form action="<?php print $gateway->getPaymentUrl(); ?>" method="POST">
<?php
$fields = $gateway->getPaymentFields();
foreach ($fields as $name => $content) {
?><span style="width:200px;display:block;float:left;clear:left;text-align:right;padding-right:5px;"><?php print $name; ?></span><input style="display:block;float:left;width:320px" type="text" name="<?php print $name; ?>" value="<?php print $content; ?>"/><br/>
<?php
}
?>
<div style="clear:both;"></div>
<input type="submit" value="Proceed to the bank"/>
</form>
<?php
if ($gateway->hasQueryAbility()) {
?>
<h3>Query (in development)</h3>
<form action="<?php print $gateway->getQueryUrl(); ?>" method="POST">
<?php
$fields = $gateway->getQueryFields();
foreach ($fields as $name => $content) {
?><span style="width:200px;display:block;float:left;clear:left;text-align:right;padding-right:5px;"><?php print $name; ?></span><input style="display:block;float:left;width:320px" type="text" name="<?php print $name; ?>" value="<?php print $content; ?>"/><br/>
<?php
}
?>
<div style="clear:both;"></div>
<input type="submit" value="Proceed to the bank"/>
</form>
<?php
}
if ($gateway->hasRefundAbility()) {
?>
<h3>Refund (mostly unimplemented)</h3>
<form action="<?php print $gateway->getRefundUrl(); ?>" method="POST">
<?php
$fields = $gateway->getRefundFields();
foreach ($fields as $name => $content) {
?><span style="width:200px;display:block;float:left;clear:left;text-align:right;padding-right:5px;"><?php print $name; ?></span><input style="display:block;float:left;width:320px" type="text" name="<?php print $name; ?>" value="<?php print $content; ?>"/><br/>
<?php
}
?>
<div style="clear:both;"></div>
<input type="submit" value="Proceed to the bank"/>
</form>
<?php
}