function commerce_paypal_ec_request_banner_account in Commerce PayPal 7.2
1 call to commerce_paypal_ec_request_banner_account()
- commerce_paypal_ec_block_save in modules/
ec/ commerce_paypal_ec.module - Implements hook_block_save().
File
- modules/
ec/ commerce_paypal_ec.module, line 1843 - Implements PayPal Express Checkout in Drupal Commerce checkout.
Code
function commerce_paypal_ec_request_banner_account($settings) {
$settings = (array) variable_get('commerce_paypal_ec_banners_settings', array()) + commerce_paypal_ec_banners_default_settings();
$data = array(
'bnCode' => PAYPAL_BANNER_BN_CODE,
'emailAddress' => $settings['api_email'],
);
// A timestamp value in milliseconds since Epoch.
$timestamp = round(microtime(TRUE) * 1000);
$token = sha1($settings['api_secret'] . $timestamp);
// @todo Replace with drupal_http_request().
$headers = array(
'Authorization: FPA ' . $settings['api_key'] . ':' . $token . ':' . $timestamp,
'Content-Type: application/json',
'Accept: application/json',
);
$ch = curl_init(commerce_paypal_ec_banner_url($settings['server']));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
curl_close($ch);
if (($result = drupal_json_decode($response)) && is_array($result)) {
if (isset($result['errors'])) {
watchdog('commerce_paypal_ec', 'The server was not able to get the banner account. The request returned from PayPal with the following data: !data', array(
'!data' => '<pre>' . check_plain(print_r($result, TRUE)) . '</pre>',
), WATCHDOG_ERROR);
drupal_set_message(t('An error occurred during account validation. Double check the e-mail address you entered and try again.'), 'error');
}
return $result;
}
watchdog('commerce_paypal_ec', 'The PayPal banners server could not be reached.', WATCHDOG_ERROR);
drupal_set_message(t('The PayPal banners server could not be reached. Please, try again.'), 'error');
return $response;
}