-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqa-donations-payzone-page.php
120 lines (100 loc) · 4.92 KB
/
qa-donations-payzone-page.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
<?php
class qa_donations_payzone_page {
const CURRENCY = 'MAD';
const ORDER_ID = 1234;
const PAYMENT_TYPE = 'CreditCard';
const SHIPPING_TYPE = 'Virtual';
const PAYMENT_MODE = 'Single';
const MERCHANT_EMAIL = '[email protected]';
const CONNECT_GATEWAY = 'https://paiement.payzone.ma';
function match_request($request)
{
$parts=explode('/', $request);
return $parts[0]=='donation' && isset($parts[1]) && intval($parts[1])%50==0 && intval($parts[1])>0 ;
}
function process_request($request)
{
$parts=explode('/', $request);
$parts[1] = $amount = intval($parts[1]);
if (qa_clicked('ok') && qa_is_http_post()) {
require_once QA_INCLUDE_DIR.'qa-db-metas.php';
require_once 'Connect2PayClient.php';
$connect2pay = 'https://paiement.payzone.ma';
$merchant = qa_opt('payzone_merchant_id');
$password = qa_opt('payzone_merchant_password');
/*
* Initialize the payment using the class Connect2PayClient.php
* */
$c2pClient = new Connect2PayClient(self::CONNECT_GATEWAY, $merchant, $password);
$first_name = qa_post_text('first_name');
$last_name = qa_post_text('last_name_name');
$phone = qa_post_text('phone_number');
$userId = qa_get_logged_in_userid()?qa_get_logged_in_userid():qa_cookie_get_create();
$c2pClient->setOrderID(self::ORDER_ID);
$c2pClient->setCurrency(self::CURRENCY);
$c2pClient->setAmount($amount*100);
$c2pClient->setPaymentType(self::PAYMENT_TYPE);
$c2pClient->setShippingType(self::SHIPPING_TYPE);
$c2pClient->setPaymentMode(self::PAYMENT_MODE);
$c2pClient->setMerchantNotificationTo(self::MERCHANT_EMAIL);
$c2pClient->setShopperFirstName($first_name);
$c2pClient->setShopperLastName($last_name);
$c2pClient->setShopperPhone($phone);
$c2pClient->setCtrlRedirectURL(qa_opt('site_url').'thank-you');
$c2pClient->setCtrlCallbackURL(qa_opt('site_url').'process-donation');
if ($c2pClient->validate()) {
$c2pClient->prepareTransaction();
// Create the payment transaction on the payment pa
// We can save in session the token info returned by the payment page (could
// be used later when the customer will return from the payment page)
$_SESSION['merchantToken'] = $code = $c2pClient->getMerchantToken();
qa_db_query_sub(
'INSERT INTO ^donators (userid, date, amount,phone, code,status)'.
'VALUES ($,NOW(), $, $, $, 0)',
$userId, $amount, $phone, $code
);
// If setup is correct redirect the customer to the payment page.
header('Location: ' . $c2pClient->getCustomerRedirectURL().'?lang=fr');
}
else {
echo "error validate: ";
echo $c2pClient->getClientErrorMessage() . "\n";
}
}
$qa_content=qa_content_prepare();
$qa_content['title']=str_replace('^1',qa_opt('site_title'),qa_lang_html('plugin_donations_payzone/donation_title'));
$qa_content['custom'] =str_replace(['^1','^2'],['<b>'.qa_opt('site_title').'</b>','<b>'.$parts[1].'</b>'],qa_lang_html('plugin_donations_payzone/donation_body'));
$qa_content['form']=array(
'tags' => 'method="post" action="'.qa_self_html().'"',
'style' => 'tall',
'title' => qa_lang_html('plugin_donations_payzone/tell_us_about_you'),
'fields' => array(
'first_name' => array(
'label' => qa_lang_html('plugin_donations_payzone/first_name'),
'tags' => 'name="first_name"',
'value' => '',
# 'error' => qa_html('Another error'),
),
'last_name' => array(
'label' => qa_lang_html('plugin_donations_payzone/last_name'),
'tags' => 'name="last_name"',
'value' => '',
),
'phone_number' => array(
'label' => qa_lang_html('plugin_donations_payzone/phone_number'),
'tags' => 'name="phone_number"',
'value' => '',
),
),
'buttons' => array(
'ok' => array(
'tags' => 'name="ok" type="submit" ',
'label' => qa_lang_html('plugin_donations_payzone/proceed'),
'value' => '1',
),
),
);
$qa_content['custom_2'] = 'سوف تتجهون لموقع Payzone.ma حيث يمكنكم إكمال إجراءات الدعم بكل أمان ببطاقتكم البنكية الوطنية.';
return $qa_content;
}
}