forked from paymentwall/module-whmcs
/
paymentwall.php
92 lines (85 loc) · 3.65 KB
/
paymentwall.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
<?php
function paymentwall_config()
{
$configarray = array(
"FriendlyName" => array("Type" => "System", "Value" => "Paymentwall"),
"appKey" => array("FriendlyName" => "Project Key", "Type" => "text", "Size" => "20",),
"secretKey" => array("FriendlyName" => "Secret Key", "Type" => "text", "Size" => "20",),
"widget" => array("FriendlyName" => "Widget", "Type" => "text", "Size" => "5",),
"isTest" => array("FriendlyName" => "Is Test", "Type" => "yesno", "Size" => "5",),
"enableDeliveryApi" => array("FriendlyName" => "Enable Delivery Api", "Type" => "yesno", "Size" => "5",),
);
return $configarray;
}
function init_paymentwall_config($params)
{
require_once(getcwd() . '/includes/api/paymentwall_api/lib/paymentwall.php');
Paymentwall_Config::getInstance()->set(array(
'api_type' => Paymentwall_Config::API_GOODS,
'public_key' => $params['appKey'], // available in your Paymentwall merchant area
'private_key' => $params['secretKey'] // available in your Paymentwall merchant area
));
}
function paymentwall_link($params)
{
init_paymentwall_config($params);
$shippingParams = getShippingParams($params);
$extraParams = array_merge(
$shippingParams,
array(
'integration_module' => 'whmcs',
'is_test' => (isset($params['isTest']) && $params['isTest'] != '') ? 1 : 0
)
);
$widget = new Paymentwall_Widget(
$params['clientdetails']['email'],
$params['widget'],
array(
new Paymentwall_Product(
(int)$params['invoiceid'],
$params['amount'],
$params['currency'],
$params["description"],
Paymentwall_Product::TYPE_FIXED
)
),
$extraParams
);
$widgetUrl = $widget->getUrl();
$code = '<form method=POST action="' . $widgetUrl . '"><a href="' . $widgetUrl .'"><img src="' . $params['systemurl'] . '/images/paymentwall/button_buy_white_yellow.png" alt="Paymentwall logo" height="34" width="153" /></a></form>';
return $code;
}
function getShippingParams($params)
{
return array(
'customer' => array(
'email' => $params['clientdetails']['email'],
'firstname' => $params['clientdetails']['firstname'],
'lastname' => $params['clientdetails']['lastname'],
'street1' => $params['clientdetails']['address1'],
'street2' => $params['clientdetails']['address2'],
'city' => $params['clientdetails']['city'],
'state' => $params['clientdetails']['state'],
'postcode' => $params['clientdetails']['postcode'],
'country' => $params['clientdetails']['country'],
'phone' => $params['clientdetails']['phonenumber']
),
'shipping_address' => array(
'firstname' => $params['clientdetails']['firstname'],
'lastname' => $params['clientdetails']['lastname'],
'company' => $params['companyname'],
'street1' => $params['clientdetails']['address1'],
'street2' => $params['clientdetails']['address2'],
'city' => $params['clientdetails']['city'],
'state' => $params['clientdetails']['state'],
'postcode' => $params['clientdetails']['postcode'],
'country' => $params['clientdetails']['country'],
'phone' => $params['clientdetails']['phonenumber']
),
'shipping_fee' => array(
'amount' => 0,
'currency' => $params['currency']
)
);
}
?>