-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheckOut.php
175 lines (148 loc) · 6.01 KB
/
checkOut.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
$config = require(dirname(__FILE__) . "/conf/config.php");
require(dirname(__FILE__) . "/lib/oApi.php");
require(dirname(__FILE__) . "/lib/oDb.php");
require(dirname(__FILE__) . "/lib/oLog.php");
$oLog = new oLog();
/* Check if we get PayPal infos */
if(isset($_GET['token']) && isset($_GET['PayerID'])) {
$oLog->infoLog("Incoming Payment !");
$payToken = $_GET['token'];
$oLog->infoLog("Validating payment..");
$oApiReq = new oApi();
$oApiReq->setUrl($config['devMode'] ? "https://api-3t.sandbox.paypal.com/nvp" : "https://api-3t.paypal.com/nvp");
/* Get payment info */
$checkOutInfos = $oApiReq->sendRequest(Array(
/* Method & version */
'METHOD' => 'GetExpressCheckoutDetails',
'VERSION' => '204',
/* Athentification */
'USER' => $config['devMode'] ? $config['devApiCred']['user'] : $config['apiCred']['user'],
'PWD' => $config['devMode'] ? $config['devApiCred']['pass'] : $config['apiCred']['pass'],
'SIGNATURE' => $config['devMode'] ? $config['devApiCred']['signature'] : $config['apiCred']['signature'],
'TOKEN' => $payToken,
));
/* Execute payment (Note the array_merge, we reuse previous Api response...) */
$oApiResp = $oApiReq->sendRequest(array_merge(
Array(
/* Method & version */
'METHOD' => 'DoExpressCheckoutPayment',
'VERSION' => '204',
/* Athentification */
'USER' => $config['devMode'] ? $config['devApiCred']['user'] : $config['apiCred']['user'],
'PWD' => $config['devMode'] ? $config['devApiCred']['pass'] : $config['apiCred']['pass'],
'SIGNATURE' => $config['devMode'] ? $config['devApiCred']['signature'] : $config['apiCred']['signature']
), $checkOutInfos));
/* Prepare page */
print("
<!DOCTYPE html>
<html>
<head>
<!-- Meta -->
<meta charset=\"utf-8\">
<!-- Title -->
<title>Devenez adhérent</title>
<!-- Stylesheets -->
<link href=\"https://fonts.googleapis.com/css?family=Open+Sans\" rel=\"stylesheet\">
<link rel=\"stylesheet\" href=\"assets/css/reset.css\">
<link rel=\"stylesheet\" href=\"assets/css/style.css\">
</head>
<body>");
if($oApiResp['ACK'] != "Success") {
/* Display error page */
$errorCode = $oApiResp['L_ERRORCODE0'];
$errorMessage = $oApiResp['L_LONGMESSAGE0'];
$oLog->errorLog(" Fail. (" . $errorCode . ": " . $errorMessage . ")");
/* Display error page */
print("
<div class=\"container\">
<h1>Oops, une erreur s'est produite !</h1>
<br>
<p>
Nous sommes désolés, mais un erreur s'est produite.. Nous mettons tout en ordre pour résoudre votre problème !<br>
L'erreur suivante s'est produite : (" . $errorCode . ": " . $errorMessage . ")
</p>
<div class=\"status\">
<div class=\"failure\"></div>
</div>
</div>
<div class=\"go-back\">
<a href=\"./\">Revenir au formulaire</a>
</div>");
exit;
} else {
$oLog->infoLog(" Success.");
/* Success ! Call FabManager's api and execute flags script(s) if any */
$oReq = $oDb->prepare('SELECT * FROM `fab-pay-form` WHERE `paymentId` = ?');
$oReq->execute(Array($oApiResp['TOKEN']));
$serverAnswer = $oReq->fetch();
$oLog->infoLog("Adding client to FabManager with API..");
/* Add client */
$FabManagerAPI = new oApi();
$FabManagerAPI->setUrl($config['fabApiUrl'] . '/user/create_account');
$FabManagerReq = Array(
'key' => $config['fabApiKey'],
'gender' => ($serverAnswer['gender'] ? 'homme' : 'femme'),
'familyName' => $serverAnswer['lastName'],
'firstName' => $serverAnswer['firstName'],
'email' => $serverAnswer['emailAddr'],
'montant' => $config['payOptions'][$serverAnswer['membershipType']][0],
'frequence' => $config['payOptions'][$serverAnswer['membershipType']][1],
'birthday' => $serverAnswer['birthDate'],
'address' => $serverAnswer['address'],
'city' => $serverAnswer['city'],
'postCode' => $serverAnswer['postCode'],
'country' => $serverAnswer['country'],
'tel' => $serverAnswer['phoneNumber']
);
$apiAnsw = $FabManagerAPI->sendRequest($FabManagerReq, true);
/* Log error if any */
if (!isset($apiAnsw['success'])) {
$oLog->infoLog(" Fail. (" . print_r($apiAnsw, true) . ")");
} else {
$oLog->infoLog(" Success.");
}
$oLog->infoLog("Adding transaction to FabManager with API..");
/* Add transaction */
$FabManagerAPI->setUrl($config['fabApiUrl'] . '/cotisation/add');
$FabManagerReq = Array(
'key' => $config['fabApiKey'],
'user_id' => $apiAnsw['user_id'],
'price' => $config['payOptions'][$serverAnswer['membershipType']][0],
'duration' => $config['payOptions'][$serverAnswer['membershipType']][1],
);
$apiAnsw = $FabManagerAPI->sendRequest($FabManagerReq, true);
/* Log error if any */
if (!isset($apiAnsw['success'])) {
$oLog->infoLog(" Fail. (" . print_r($apiAnsw, true) . ")");
} else {
$oLog->infoLog(" Success.");
}
// Exec flags, later //
// Send mail, later //
/* Display success page */
print("
<div class=\"container\">
<h1>Et voilà, c'est fait !</h1>
<br>
<p>
Toute nos félicitations, vous êtes désormais l'un de nos membres. Bienvenue à Avilab, cher maker !
</p>
<div class=\"status\">
<div class=\"success\"></div>
</div>
</div>
<div class=\"go-back\">
<a href=\"http://www.avilab.fr\">Revenir sur avilab.fr</a>
</div>");
}
/* End page */
print("
</body>
</html>");
} else {
/* Redirect to main page if not $_GET infos */
header("Location: ./");
exit;
}
?>