-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRedirectVACIMBNiagaExample.php
66 lines (59 loc) · 1.72 KB
/
RedirectVACIMBNiagaExample.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
/**
* RedirectVACIMBNiagaExample.php.
*
* @author Ferdhika Yudira
* @email fer@dika.web.id
*/
require './vendor/autoload.php';
use ferdhika31\iPaymuPHP\Exceptions\InvalidApiKeyException;
use ferdhika31\iPaymuPHP\Exceptions\InvalidArgumentException;
use ferdhika31\iPaymuPHP\iPaymu;
use ferdhika31\iPaymuPHP\PaymentRedirect;
$config = [
'env' => 'SANDBOX',
'virtual_account' => 'your_virtual_account',
'api_key' => 'your_api_key',
'notify_uri' => 'http://localhost:8000/notify',
'cancel_uri' => 'http://localhost:8000/cancel',
'return_uri' => 'http://localhost:8000/return',
];
try {
iPaymu::init($config);
// optional
$customer = [
'name' => 'Dika',
'email' => 'fer@dika.web.id',
'phone' => '083213123332',
];
iPaymu::setCustomer($customer);
$products = [
[
'name' => 'Mangga',
'qty' => 2,
'price' => 2500,
'description' => 'Mangga cobian',
],
[
'name' => 'Jeruk',
'qty' => 1,
'price' => 5000,
'description' => 'Jeruk asem',
],
];
foreach ($products as $product) {
iPaymu::addProduct($product);
}
// optional
$payloadTrx = [
'expired' => 5, // in hours
'comments' => 'Transaction comment here',
'referenceId' => 'TRX202008310001',
];
$redirectPayment = PaymentRedirect::niagaVA()->create($payloadTrx);
var_dump($redirectPayment);
} catch (InvalidApiKeyException $e) {
echo $e->getMessage();
} catch (InvalidArgumentException $e) {
echo $e->getMessage();
}