Only other thought is something in the PayPal API request might be causing it to fail
public function apiRequest($endpoint, $data = '', $auth_check = false, $tab_pay = array())
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.'.((int)Configuration::get('PAYPALPRO_SANDBOX') ? 'sandbox.' : '').'paypal.com/v1/oauth2/token');
curl_setopt($ch, CURLOPT_USERPWD, pSQL(Configuration::get('PAYPALPRO_CLIENT_ID')).':'.Configuration::get('PAYPALPRO_SECRET_KEY'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, !in_array($_SERVER['REMOTE_ADDR'], array('localhost', '::1')));
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'grant_type=client_credentials');
$result = curl_exec($ch);
curl_close($ch);
/* Check if authentication is valid */
if ($result)
{
$result_json = Tools::jsonDecode($result);
if (isset($result_json->access_token))
{
if ($auth_check)
return true;
if ($data != '{}')
$enc_data = Tools::jsonEncode($data);
else
$enc_data = $data;
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, 'https://api.'.(Configuration::get('PAYPALPRO_SANDBOX') ? 'sandbox.' : '').'paypal.com/'.$endpoint);
curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, !in_array($_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1')));
curl_setopt($ch2, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch2, CURLOPT_VERBOSE, true);
curl_setopt($ch2, CURLOPT_POST, true);
curl_setopt($ch2, CURLOPT_POSTFIELDS, $enc_data);
curl_setopt($ch2, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Bearer '.$result_json->access_token,
'PayPal-Partner-Attribution-Id: PrestashopUS_Cart'
));
$result = curl_exec($ch2);
$json_result = Tools::jsonDecode($result);
curl_close($ch2);
if (isset($json_result->state))
{
/* The payment was approved */
if ($json_result->state == 'approved' && $json_result->intent == 'sale' && isset($json_result->id) && $json_result->id)
{
$id_paypal = $json_result->transactions[0]->related_resources[0]->sale->id;
$message = 'Transaction ID: '.$json_result->id;
/* Check currency $json_result->transactions[0]->amount->currency */
try
{
$this->validateOrder((int)$this->context->cart->id, (int)Configuration::get('PS_OS_PAYMENT'),
(float)$json_result->transactions[0]->amount->total, $this->l('Payment by Paypal Pro'), $message,
array(), null, false, $this->context->customer->secure_key);
}
catch (PrestaShopException $e)
{
$this->_error[] = (string)$e->getMessage();
}
$this->addTentative(Tools::substr($data['payer']['funding_instruments'][0]['credit_card']['number'], 0, 4),
$data['payer']['funding_instruments'][0]['credit_card']['type'], 1, $id_paypal);
$id_order = Order::getOrderByCartId($this->context->cart->id);
die(Tools::jsonEncode(array('code' => '1', 'url' => __PS_BASE_URI__.'index.php?controller=order-confirmation&id_cart='.
(int)$this->context->cart->id.'&id_module='.(int)$this->id.'&id_order='.(int)$id_order.
'&key='.$this->context->customer->secure_key)));
}
/* Refund Payment was approved */
else if ($json_result->state == 'completed' && !empty($tab_pay['id_cart']))
{
$this->addTentative($tab_pay['last_digits'], $tab_pay['cc_type'], 2, 0, $tab_pay['id_cart']);
$id_order = Order::getOrderByCartId($tab_pay['id_cart']);
$order = new Order($id_order);
/* Refund State */
$order->setCurrentState(7);
Tools::redirect($tab_pay['redirect']);
}
/* The payment was declined */
else
{
$this->addTentative(Tools::substr($data['payer']['funding_instruments'][0]['credit_card']['number'], 0, 4),
$data['payer']['funding_instruments'][0]['credit_card']['type'], 0, 0);
if ($json_result->state == 'expired')
die(Tools::jsonEncode(array('code' => '0', 'msg' => $this->l('Payment declined. This card has expired, please use another one.'))));
else
die(Tools::jsonEncode(array('code' => '0', 'msg' => $this->l('Payment declined. Please use another card.'))));
}
}
else
{
if ($json_result->name == 'TRANSACTION_REFUSED' && !empty($tab_pay))
Tools::redirect($tab_pay['redirect']);
else
{
$this->addTentative(Tools::substr($data['payer']['funding_instruments'][0]['credit_card']['number'], 0, 4),
$data['payer']['funding_instruments'][0]['credit_card']['type'], 0, 0);
die(Tools::jsonEncode(array('code' => '0',
'msg' => $this->l('Payment declined. Unknown error, please use another card or contact us.'))));
}
}
}
else
{
if ($auth_check)
return false;
die(Tools::jsonEncode(array('code' => '0', 'msg' => $this->l('Invalid PayPal Pro credentials, please check your configuration.'))));
}
}
else
{
if ($auth_check)
return false;
die(Tools::jsonEncode(array('code' => '0', 'msg' => $this->l('Invalid PayPal Pro credentials, please check your configuration.'))));
}
}
/*
** @Method: name
** @description: description
**
** @arg:
** @return: (none)
*/
Source Files - https://ufile.io/iv53w