8 require_once(
"ChPmtProvider.php");
10 define(
'PP_MODE_LIVE', 1);
11 define(
'PP_MODE_TEST', 2);
13 define(
'PP_PRC_TYPE_DIRECT', 1);
14 define(
'PP_PRC_TYPE_PDT', 2);
15 define(
'PP_PRC_TYPE_IPN', 3);
27 $this->_bRedirectOnResult =
false;
29 $this->_sDataReturnUrl = $this->_oConfig->getDataReturnUrl() . $this->_sName .
'/';
31 public function initializeCheckout($iPendingId, $aCartInfo, $bRecurring =
false, $iRecurringDays = 0)
34 $sActionURL = $iMode ==
PP_MODE_LIVE ?
'https://www.paypal.com/cgi-bin/webscr' :
'https://www.sandbox.paypal.com/cgi-bin/webscr';
38 'cmd' =>
'_xclick-subscriptions',
39 'a3' => sprintf(
"%.2f", (
float)$aCartInfo[
'items_price']),
40 'p3' => $iRecurringDays,
48 'amount' => sprintf(
"%.2f", (
float)$aCartInfo[
'items_price'])
52 $aFormData = array_merge($aFormData, array(
55 'item_name' =>
_t(
'_payment_txt_payment_to', $aCartInfo[
'vendor_username']),
56 'item_number' => $iPendingId,
57 'currency_code' => $aCartInfo[
'vendor_currency_code'],
60 'custom' => md5($aCartInfo[
'vendor_id'] . $iPendingId)
64 foreach ($aCartInfo[
'items']
as $aItem) {
65 $aFormData[
'item_name'] .=
' ' . (
$iIndex++) .
'. ' . $aItem[
'title'];
71 $aFormData = array_merge($aFormData, array(
72 'return' => $this->_sDataReturnUrl . $aCartInfo[
'vendor_id'],
77 $aFormData = array_merge($aFormData, array(
78 'return' => $this->_oConfig->getReturnUrl(),
79 'notify_url' => $this->_sDataReturnUrl . $aCartInfo[
'vendor_id'],
85 Redirect($sActionURL, $aFormData,
'post', $this->_sCaption);
94 if ($aData[
'txn_type'] ==
'web_accept' || $aData[
'txn_type'] ==
'cart' || $aData[
'tx'] !=
'') {
98 return array(
'code' => 2,
'message' =>
_t(
'_payment_pp_err_no_data_given'));
112 if (
empty($this->_aOptions) && isset($aData[
'item_number'])) {
116 if (
empty($this->_aOptions)) {
117 return array(
'code' => -1,
'message' =>
_t(
'_payment_pp_err_no_vendor_given'));
120 $iPrcType = (int)$this->
getOption(
'prc_type');
124 return array(
'code' => 2,
'message' =>
_t(
'_payment_pp_err_no_data_given'));
126 return array(
'code' => 2,
'message' =>
_t(
'_payment_pp_err_no_data_given'));
132 $aResult = array(
'code' => 1,
'message' =>
_t(
'_payment_pp_msg_verified'));
134 if (!$bSubscription ||
empty($iPendingId)) {
135 $iPendingId = (int)$aData[
'item_number1'];
138 $aPending = $this->_oDb->getPending(array(
'type' =>
'id',
'id' => $iPendingId));
139 if (!
empty($aPending[
'order']) || !
empty($aPending[
'error_code']) || !
empty($aPending[
'error_msg']) || (int)$aPending[
'processed'] != 0) {
140 return array(
'code' => -1,
'message' =>
_t(
'_payment_pp_err_already_processed'));
144 $this->_oDb->updatePending($iPendingId, array(
145 'order' => $aData[
'txn_id'],
154 $aResult[
'pending_id'] = $iPendingId;
155 $aResult[
'payer_name'] =
_t(
'_payment_txt_buyer_name_mask', $sBuyerFirstName, $sBuyerLastName);
156 $aResult[
'payer_email'] = $sBuyerEmail;
166 $sBusiness = $this->
getOption(
'business');
167 $sConnectionUrl =
'www.paypal.com';
169 $sBusiness = $this->
getOption(
'sandbox');
170 $sConnectionUrl =
'www.sandbox.paypal.com';
173 $iPrcType = $this->
getOption(
'prc_type');
175 if ($aData[
'payment_status'] !=
'Completed') {
176 return array(
'code' => 0,
'message' =>
_t(
'_payment_pp_err_not_completed'));
179 if ($aData[
'business'] != $sBusiness) {
180 return array(
'code' => -1,
'message' =>
_t(
'_payment_pp_err_wrong_business'));
183 $sRequest =
'cmd=_notify-validate';
184 foreach ($aData
as $sKey => $sValue) {
185 if (in_array($sKey, array(
'cmd'))) {
189 $sRequest .=
'&' . urlencode($sKey) .
'=' . urlencode(
process_pass_data($sValue));
193 if ((
int)$aResponse[
'code'] !== 0) {
197 array_walk($aResponse[
'content'],
function (&$arg) {
200 if (strcmp($aResponse[
'content'][0],
"INVALID") === 0) {
201 return array(
'code' => -1,
'message' =>
_t(
'_payment_pp_err_wrong_transaction'));
202 } elseif (strcmp($aResponse[
'content'][0],
"VERIFIED") !== 0) {
203 return array(
'code' => 2,
'message' =>
_t(
'_payment_pp_err_wrong_verification_status'));
206 $sRequest =
"cmd=_notify-synch&tx=" . $aData[
'tx'] .
"&at=" . $this->
getOption(
'token');
209 if ((
int)$aResponse[
'code'] !== 0) {
213 if (strcmp($aResponse[
'content'][0],
"FAIL") === 0) {
214 return array(
'code' => -1,
'message' =>
_t(
'_payment_pp_err_wrong_transaction'));
215 } elseif (strcmp($aResponse[
'content'][0],
"SUCCESS") !== 0) {
216 return array(
'code' => 2,
'message' =>
_t(
'_payment_pp_err_wrong_verification_status'));
220 foreach ($aResponse[
'content']
as $sLine) {
221 list($sKey, $sValue) = explode(
"=", $sLine);
222 $aKeys[urldecode($sKey)] = urldecode($sValue);
225 $aData = array_merge($aData, $aKeys);
227 if ($aData[
'payment_status'] !=
'Completed') {
228 return array(
'code' => 0,
'message' =>
_t(
'_payment_pp_err_not_completed'));
231 if ($aData[
'business'] != $sBusiness) {
232 return array(
'code' => -1,
'message' =>
_t(
'_payment_pp_err_wrong_business'));
236 $aPending = $this->_oDb->getPending(array(
'type' =>
'id',
'id' => $aData[
'item_number']));
237 $aVendor = $this->_oDb->getVendorInfoProfile($aPending[
'seller_id']);
239 if ($fAmount != (
float)$aPending[
'amount']) {
240 return array(
'code' => -1,
'message' =>
_t(
'_payment_pp_err_wrong_amount'));
243 if ($aData[
'custom'] != md5($aPending[
'seller_id'] . $aPending[
'id'])) {
244 return array(
'code' => -1,
'message' =>
_t(
'_payment_pp_err_wrong_custom_data'));
247 return array(
'code' => 1,
'message' =>
_t(
'_payment_pp_msg_verified'));
252 $rConnect = curl_init(
'https://' . $sConnectionUrl .
'/cgi-bin/webscr');
253 curl_setopt($rConnect, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
254 curl_setopt($rConnect, CURLOPT_POST, 1);
255 curl_setopt($rConnect, CURLOPT_RETURNTRANSFER, 1);
256 curl_setopt($rConnect, CURLOPT_POSTFIELDS, $sRequest);
257 curl_setopt($rConnect, CURLOPT_SSL_VERIFYPEER, 1);
258 curl_setopt($rConnect, CURLOPT_SSL_VERIFYHOST, 2);
259 curl_setopt($rConnect, CURLOPT_FORBID_REUSE, 1);
260 curl_setopt($rConnect, CURLOPT_HTTPHEADER, array(
'Connection: Close'));
262 $sResponse = curl_exec($rConnect);
263 if (curl_errno($rConnect) == 60) {
264 curl_setopt($rConnect, CURLOPT_CAINFO, CH_DIRECTORY_PATH_PLUGINS .
'curl/cacert.pem');
265 $sResponse = curl_exec($rConnect);
268 curl_close($rConnect);
270 return array(
'code' => 6,
'message' => $this->_sLangsPrefix .
'err_cannot_validate');
273 return array(
'code' => 0,
'content' => explode(
"\n", $sResponse));
279 $fTax = isset($aResultData[
'tax']) ? (float)$aResultData[
'tax'] : 0.00;
281 if ($aResultData[
'mc_currency'] == $sCurrencyCode && isset($aResultData[
'payment_gross']) && !
empty($aResultData[
'payment_gross'])) {
282 $fAmount = (float)$aResultData[
'payment_gross'] - $fTax;
283 } elseif ($aResultData[
'mc_currency'] == $sCurrencyCode && isset($aResultData[
'mc_gross']) && !
empty($aResultData[
'mc_gross'])) {
284 $fAmount = (float)$aResultData[
'mc_gross'] - $fTax;
285 } elseif ($aResultData[
'settle_currency'] == $sCurrencyCode && isset($aResultData[
'settle_amount']) && !
empty($aResultData[
'settle_amount'])) {
286 $fAmount = (float)$aResultData[
'settle_amount'] - $fTax;