-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDirectCODExample.php
65 lines (58 loc) · 1.7 KB
/
DirectCODExample.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
<?php
/**
* DirectCODExample.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\PaymentDirect;
$config = [
'env' => 'SANDBOX',
'virtual_account' => 'your_virtual_account',
'api_key' => 'your_api_key',
'notify_uri' => 'http://localhost:8000/notify',
];
try {
iPaymu::init($config);
$customer = [
'name' => 'Dika',
'email' => 'fer@dika.web.id',
'phone' => '083213123332',
];
iPaymu::setCustomer($customer);
iPaymu::addProduct([
'name' => 'Mangga',
'qty' => 2,
'price' => 2500,
'weight' => 2, // in kilogram
'length' => 10, // in cm
'width' => 20, // in cm
'height' => 20, // in cm
]);
$payloadTrx = [
'amount' => 5000,
// optional
'expired' => 10,
'expiredType' => 'minutes', // in:seconds,minutes,hours,days
'description' => 'Description comment here',
'referenceId' => 'TRX202008310001',
];
$payloadCOD = [
'deliveryArea' => '40391',
'deliveryAddress' => 'Lembang',
// optional
'pickupArea' => '40391',
'pickupAddress' => 'Lembang',
'splitCount' => 1,
];
$directPayment = PaymentDirect::COD($payloadCOD)->create($payloadTrx);
var_dump($directPayment);
} catch (InvalidApiKeyException $e) {
echo $e->getMessage();
} catch (InvalidArgumentException $e) {
echo $e->getMessage();
}