-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
67 lines (58 loc) · 2.46 KB
/
index.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
<?php
if (!class_exists('Paymentwall_Config')) {
require_once(__DIR__ . '/lib/paymentwall.php');
}
Paymentwall_Config::getInstance()->set(array(
'private_key' => 'YOUR_PRIVATE_KEY',
'public_key' => 'YOUR_PUBLIC_KEY'
));
$webhook = file_get_contents('php://input');
$fulfillment = json_decode($webhook, TRUE);
callDeliveryApi($fulfillment);
/**
* Call Delivery API
* @param $fulfillment [description]
* @return
*/
function callDeliveryApi ($fulfillment)
{
$delivery = new Paymentwall_GenerericApiObject('delivery');
return $delivery->post(prepareDeliveryData($fulfillment));
}
/**
* Prepare Delivery Data
* @param $fulfillment
* @return array
*/
function prepareDeliveryData ($fulfillment)
{
$data = array(
'payment_id' => $fulfillment['order_id'],
'merchant_reference_id' => $fulfillment['order_id'],
'status' => 'delivered',
'estimated_delivery_datetime' => $fulfillment['created_at'],
'estimated_update_datetime' => $fulfillment['updated_at'],
'refundable' => true,
'details' => 'Item will be delivered via email by ' . $fulfillment['created_at'],
'shipping_address[email]' => $fulfillment['email'],
'shipping_address[firstname]' => $fulfillment['destination']['first_name'],
'shipping_address[lastname]' => $fulfillment['destination']['last_name'],
'shipping_address[country]' => $fulfillment['destination']['country'],
'shipping_address[street]' => $fulfillment['destination']['address1'],
'shipping_address[state]' => $fulfillment['destination']['province_code'] ? $fulfillment['destination']['province_code'] : 'NA',
'shipping_address[phone]' => $fulfillment['destination']['phone'] ? $fulfillment['destination']['phone'] : 'NA',
'shipping_address[zip]' => $fulfillment['destination']['zip'],
'shipping_address[city]' => $fulfillment['destination']['city'],
'carrier_type' => $fulfillment['tracking_company'],
'reason' => 'none',
'carrier_trackind_id' => $fulfillment['tracking_number'],
'is_test' => 1
);
if(!empty($fulfillment['destination'])) {
$data['type'] = 'physical';
} else {
$data['type'] = 'digital';
}
return $data;
}
?>