public function StripePaymentMethodController::retrieveToken in Stripe 7
Retrieve the Stripe Token object for a given Payment.
This method handles Stripe errors and logs them to Drupal's watchdog. If the user as view access to the Payment object, errors are also displayed as error message.
Parameters
Payment $payment: A Payment object.
Return value
\Stripe\Token The Stripe Token object for the given Payment. Or NULL if no Stripe Token could be retrieved (errors are logged to Drupal's watchdog) or if the Payment does not use Stripe.
File
- stripe_payment/
includes/ StripePaymentMethodController.inc, line 420 - Stripe Payment controller class and helper code (classes and function).
Class
Code
public function retrieveToken(Payment $payment) {
if ($payment->method->controller->name === 'StripePaymentMethodController' && $payment->method_data['token']) {
$api_key = !empty($payment->method->controller_data['keys']['mode']) ? $payment->method->controller_data['keys']['secret'] : stripe_get_key('secret');
try {
return \Stripe\Token::retrieve($payment->method_data['token'], $api_key);
} catch (\Stripe\Error $e) {
if (payment_access('view', $payment)) {
drupal_set_message(t('Unable to retrieve Stripe Token for <a href="@url">Payment</a>: @message.', array(
'@url' => url("payment/{$payment->pid}"),
'@message' => $e
->getMessage(),
)), 'error');
}
watchdog('stripe_payment', 'Unable to retrieve Stripe Token for <a href="@url">Payment</a>: @message.', array(
'@url' => url("payment/{$payment->pid}"),
'@message' => $e
->getMessage(),
), WATCHDOG_ERROR, l(t('view'), "payment/{$payment->pid}"));
}
}
return NULL;
}