function commerce_sermepa_callback in Commerce sermepa 7
Get POST response from sermepa.
1 string reference to 'commerce_sermepa_callback'
- commerce_sermepa_menu in ./
commerce_sermepa.module - Implements hook_menu().
File
- ./
commerce_sermepa.module, line 135 - Provides a payment method for Drupal Commerce using Sermepa/Redsys gateway.
Code
function commerce_sermepa_callback($order) {
if (!$order) {
watchdog('commerce_sermepa', "Bad '%order_id' order id received in feedback values.", array(
'%order_id' => arg(2),
), WATCHDOG_WARNING);
return FALSE;
}
// Load the payment method.
$payment_method = commerce_payment_method_instance_load($order->data['payment_method']);
if (!$payment_method || $payment_method['method_id'] != 'commerce_sermepa') {
watchdog('commerce_sermepa', "Unknown or non-existent '%method_id' payment method.", array(
'%method_id' => 'commerce_sermepa',
), WATCHDOG_WARNING);
return FALSE;
}
// Create a sermepa instance.
if (!($gateway = commerce_sermepa_library_initialize($payment_method['settings']))) {
return FALSE;
}
// Get response data.
if (!($feedback = $gateway
->getFeedback())) {
watchdog('commerce_sermepa', "Bad feedback response data.", array(), WATCHDOG_WARNING);
return FALSE;
}
// Get order number from feedback data and compare it with the order object
// argument.
$parameters = $gateway
->decodeMerchantParameters($feedback['Ds_MerchantParameters']);
$order_id = $parameters['Ds_MerchantData'];
if ($order_id != $order->order_id) {
watchdog('commerce_sermepa', "The order id from feedback and the order object argument id don't match.", array(), WATCHDOG_WARNING);
}
// Validate feedback values.
if (!$gateway
->validSignatures($feedback)) {
watchdog('commerce_sermepa', "Bad feedback response, signatures don't match.", array(), WATCHDOG_WARNING);
return FALSE;
}
// Process the transaction.
commerce_sermepa_process_transaction($order, $payment_method, $parameters);
return FALSE;
}