-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwocheckout.php
134 lines (93 loc) · 4.33 KB
/
twocheckout.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
<?php
hbm_create('twocheckout',array(
'description'=>'2checkout Module for HostBill by ArabHosters',
'version'=>'1.0',
'currencies'=>array('USD','EGP','SAR')
));
hbm_add_config_option('Merchant ID');
hbm_add_config_option('Secret Word');
hbm_add_config_option('Return URL');
//hbm_add_config_option('Hash Total');
hbm_on_action('payment.displayform', function($details){
$hostbill_details = hbm_get_hostbill_details();
$cc_url = 'https://www.2checkout.com/checkout/spurchase';
$merchant_id=hbm_get_config_option('Merchant ID');
//This will create url to callback route created below
$callback_url = hbm_client_url('callback');
$api = new ApiWrapper();
$return = $api->getCurrencies();
$price = $details['invoice']['amount'];
if($details['invoice']['currency'] != 'USD'){
foreach($return['currencies'] as $cur){
if($cur['iso'] == $details['invoice']['currency'])
$price = money_format('%.2n', $details['invoice']['amount']/$cur['rate']);
}
}
/*
if($details['invoice']['currency']=='SAR'){
$price = $details['invoice']['amount']/$return['currencies'][0]['rate'];
}elseif($details['invoice']['currency']=='EGP'){
$price = $details['invoice']['amount']/$return['currencies'][1]['rate'];
}else{
$price = $details['invoice']['amount'];
}
*/
$form = '<form action="'.$cc_url.'" method="post" name="payform">
<input type="hidden" name="skip_landing" value="1">
<input type="hidden" name="sid" value="'.$merchant_id.'">
<input type="hidden" name="lang" value="en">
<input type="hidden" name="first_name" value="'.$details['client']['firstname'].'">
<input type="hidden" name="last_name" value="'.$details['client']['lastname'].'">
<input type="hidden" name="street_address" value="'.$details['client']['address1'].'">
<input type="hidden" name="street_address2" value="'.$details['client']['address2'].'">
<input type="hidden" name="city" value="'.$details['client']['city'].'">
<input type="hidden" name="zip" value="'.$details['client']['postcode'].'">
<input type="hidden" name="country" value="'.$details['client']['country'].'">
<input type="hidden" name="state" value="'.$details['client']['state'].'">
<input type="hidden" name="phone" value="'.$details['client']['phonenumber'].'">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="total" value="'.$price.'">
<input type="hidden" name="merchant_order_id" value="'.$details['invoice']['id'].'">
<input type="hidden" name="cart_order_id" value="'.$details['invoice']['id'].'">
<input type="hidden" name="c_name" value="'.$details['invoice']['description'].'">
<input type="hidden" name="c_prod" value="'.$details['invoice']['id'].'">
<input type="hidden" name="c_price" value="'.$price.'">
<input type="hidden" name="fixed" value="Y">
<input type="hidden" name="return_url" value="'.$callback_url.'">
<input type="hidden" name="email" value="'.$details['client']['email'].'">
<input type="submit" value="ادفع الآن">
</form>';
return $form;
});
hbm_client_route('callback',function($request) {
if ($_REQUEST['demo'] == 'Y')
{
$order_number = 1;
}
else
{
$order_number = $_REQUEST['order_number'];
}
$secretWord = hbm_get_config_option('Secret Word'); //2Checkout Secret Word
$sid = hbm_get_config_option('Merchant ID'); //2Checkout account number
$string_to_hash = $secretWord.$sid.$order_number.$_POST["total"];
$check_key = strtoupper(md5($string_to_hash));
$return_url=hbm_get_config_option('Return URL');
if ($check_key != $_REQUEST['key']) {
$result = "Fail - Hash Mismatch";
echo $result;
} else {
$api = new ApiWrapper();
$params = array(
'id'=>$_POST['merchant_order_id']
);
$return = $api->getInvoiceDetails($params);
$total = $return['invoice']['total'];
hbm_log_callback($_POST,'Successfull');
hbm_add_transaction( $_POST['merchant_order_id'],$total,array(
'description' => $_POST['merchant_order_id'],
'transaction_id' => $_POST['merchant_order_id']
));
echo '<META HTTP-EQUIV="Refresh" Content="0; URL='.$return_url.$_POST['merchant_order_id'].'"/>';
}
});