function commerce_stripe_libraries_postload_callback in Commerce Stripe 7.3
Post-load callback for the Stripe PHP Library.
Parameters
array $library: An array of library information.
string $version: If the $library array belongs to a certain version, a string containing the version.
string $variant: If the $library array belongs to a certain variant, a string containing the variant name.
1 string reference to 'commerce_stripe_libraries_postload_callback'
- commerce_stripe_libraries_info in ./
commerce_stripe.module - Implements hook_libraries_info().
File
- ./
commerce_stripe.module, line 110 - This module provides Stripe (http://stripe.com/) payment gateway integration to Commerce. Commerce Stripe offers a PCI-compliant way to process payments straight from you Commerce shop.
Code
function commerce_stripe_libraries_postload_callback($library, $version = NULL, $variant = NULL) {
if (!empty($library['loaded'])) {
// @todo: Make this a global configuration, since merchants will only have one API key.
$payment_method = commerce_payment_method_instance_load('commerce_stripe|commerce_payment_commerce_stripe');
$settings = $payment_method['settings'];
// If the site is using the Commerce Stripe Connect submodule and the
// payment method is configured to use a site-wide connected account, swap
// in its secret and public key now.
if (module_exists('commerce_stripe_connect') && !empty($settings['use_connected_account']) && $settings['use_connected_account'] == 'site account') {
$connect_settings = commerce_stripe_connect_get_settings();
$settings['secret_key'] = $connect_settings['connected_secret_key'];
$settings['public_key'] = $connect_settings['connected_public_key'];
}
if (!isset($settings['secret_key']) || empty($settings['secret_key'])) {
drupal_set_message(t('Stripe secret and public key are required in order to use Stripe payment method. See README.txt for instructions.'), 'warning');
$link = l(t('configured here'), 'admin/commerce/config/payment-methods');
drupal_set_message(t('Settings required for the Stripe payment method can be !link.', array(
'!link' => $link,
)), 'warning');
return;
}
\Stripe\Stripe::setApiKey(trim($settings['secret_key']));
// If configured to, set the API Version for all requests.
// Because the default is the version configured in the Stripe
// Account dashboard, we only set the version if something else
// has been configured by an administrator.
if (!isset($settings['commerce_stripe_api_version'])) {
$api_version = COMMERCE_STRIPE_API_LATEST_TESTED;
}
else {
$api_version = $settings['commerce_stripe_api_version'];
}
if ($api_version != COMMERCE_STRIPE_API_ACCOUNT_DEFAULT) {
if ($api_version == COMMERCE_STRIPE_API_VERSION_CUSTOM) {
$api_version = check_plain($settings['commerce_stripe_api_version_custom']);
}
try {
\Stripe\Stripe::setApiVersion($api_version);
} catch (\Stripe\Error\InvalidRequest $e) {
watchdog('stripe', 'Stripe setApiVersion Exception: %error', array(
'%error' => $e
->getMessage(),
), WATCHDOG_ERROR);
drupal_set_message(t('Stripe API Error: :error', array(
':error' => $e
->getMessage(),
)), 'error');
}
}
}
}