You are here

function commerce_paypal_ec_block_save in Commerce PayPal 7.2

Implements hook_block_save().

Saves the settings filled in and request PayPal's API to get a payerId and a publisherId.

File

modules/ec/commerce_paypal_ec.module, line 1773
Implements PayPal Express Checkout in Drupal Commerce checkout.

Code

function commerce_paypal_ec_block_save($delta = '', $edit = array()) {
  if ($delta == 'commerce_paypal_ec_banners') {
    if (!empty($edit['settings'])) {

      // Clean the entered values.
      $edit['settings'] = array_map('trim', $edit['settings']);

      /**
      * Using the staging server is for now unavailable, so we simply default
      * to using the live key and secret.
      *
            if ($edit['settings']['server'] == 'live') {
       $edit['settings']['api_key'] = PAYPAL_BANNER_API_KEY;
       $edit['settings']['api_secret'] = PAYPAL_BANNER_API_SECRET;
            }
            else {
       $edit['settings']['api_key'] = PAYPAL_BANNER_API_KEY_STAGING;
       $edit['settings']['api_secret'] = PAYPAL_BANNER_API_SECRET_STAGING;
            }
      */
      $edit['settings']['api_key'] = PAYPAL_BANNER_API_KEY;
      $edit['settings']['api_secret'] = PAYPAL_BANNER_API_SECRET;

      // Gets the payerId and the publisherId.
      if (($banner_account = commerce_paypal_ec_request_banner_account($edit['settings'])) && (isset($banner_account['payerId']) && isset($banner_account['publisherId']))) {
        $edit['settings']['payerId'] = $banner_account['payerId'];
        $edit['settings']['publisherId'] = $banner_account['publisherId'];
      }
      variable_set('commerce_paypal_ec_banners_settings', $edit['settings']);
    }
  }
}