Skip to content
Snippets Groups Projects
Commit b875087f authored by project update bot's avatar project update bot Committed by Panagiotis Moutsopoulos
Browse files

Issue #3428412 by m.managoudis: Automated Drupal 11 compatibility fixes for...

Issue #3428412 by m.managoudis: Automated Drupal 11 compatibility fixes for commerce_alphabank_redirect
parent 1c69673a
No related branches found
No related tags found
1 merge request!2Automated Project Update Bot fixes
......@@ -2,7 +2,7 @@ name: Commerce Alphabank
type: module
description: 'Provides Alphabank Payment gateway.'
package: Commerce
core_version_requirement: ^8.8 || ^9 || ^10
core_version_requirement: ^8.9 || ^9 || ^10 || ^11
dependencies:
- commerce:commerce
- commerce:commerce_payment
<?php
/**
* @file
* Provides Redirection Payment method with Alphabank for Drupal Commerce.
*/
// URLs.
define('AB_PAY_COMPLETED', 'checkout/alphabank/success');
define('AB_PAY_ERROR', 'checkout/alphabank/error');
/**
* Implements hook_menu().
*/
function commerce_alphabank_redirect_menu() {
$items = array();
$items[AB_PAY_COMPLETED] = array(
'title' => 'Order complete',
'page callback' => 'commerce_alphabank_redirect_complete',
'page arguments' => array(),
'access callback' => 'commerce_alphabank_redirect_completion_access',
'type' => MENU_CALLBACK,
'file' => 'commerce_alphabank_redirect.pages.inc',
);
$items[AB_PAY_ERROR] = array(
'title' => 'Order complete',
'page callback' => 'commerce_alphabank_redirect_error',
'page arguments' => array(),
'access callback' => 'commerce_alphabank_redirect_completion_access',
'type' => MENU_CALLBACK,
'file' => 'commerce_alphabank_redirect.pages.inc',
);
return $items;
}
/**
* Make sure anyone can complete their orders through AlphaBank.
*/
function commerce_alphabank_redirect_completion_access() {
return TRUE;
}
/**
* Implements hook_static_checkout_url_links().
*/
function commerce_alphabank_redirect_static_checkout_url_links() {
return array(
'Alphabank: return link after success' => AB_PAY_COMPLETED,
'Alphabank: return link after cancelation' => AB_PAY_ERROR,
);
}
/**
* Implements hook_commerce_payment_method_info().
*/
function commerce_alphabank_redirect_commerce_payment_method_info() {
$payment_methods = array();
$payment_methods['commerce_alphabank_redirect'] = array(
'base' => 'commerce_alphabank_redirect',
'title' => t('Credit card - on a secure environment provided by Alphabank Greece'),
'display' => t('Credit Card (Alphabank)'),
'short_title' => t('Alphabank'),
'description' => t('Integration with Alphabank using redirection.'),
'active' => TRUE,
'offsite' => TRUE,
'offsite_autoredirect' => commerce_static_checkout_url_get_auto_redirect(),
);
return $payment_methods;
}
/**
* Settings form, uUsed to set vendor name and secret key within Rules settings.
*/
function commerce_alphabank_redirect_settings_form($settings = NULL) {
$form = array();
// Merge default settings into the stored settings array.
$default_currency = variable_get('commerce_default_currency', 'EUR');
$settings = (array) $settings + array(
'mid' => '',
'shared_secret_key' => '',
'post_url' => 'https://www.alphaecommerce.gr/vpos/shophandlermpi',
'transaction_type' => COMMERCE_CREDIT_AUTH_CAPTURE,
'currency_code' => in_array($default_currency, array_keys(commerce_alphabank_redirect_available_currencies())) ? $default_currency : 'EUR',
'order_description' => '',
'allow_installments' => FALSE,
'max_installments' => 0,
'merchant_name' => '',
'cancelation_policy' => '',
'payment_method_description' => 'Continue with checkout to complete payment via Alpha e-Commerce',
'send_payer_email' => 0,
);
$form['mid'] = array(
'#type' => 'textfield',
'#title' => t('Mid'),
'#description' => t('Mid from Alphabank'),
'#required' => TRUE,
'#default_value' => $settings['mid'],
);
$form['shared_secret_key'] = array(
'#type' => 'textfield',
'#title' => t('Shared secret key'),
'#description' => t('Shared secret key from Alphabank'),
'#required' => TRUE,
'#default_value' => $settings['shared_secret_key'],
);
$form['post_url'] = array(
'#type' => 'textfield',
'#title' => t('POST Url'),
'#description' => t('Url to post data'),
'#required' => TRUE,
'#default_value' => $settings['post_url'],
);
$form['transaction_type'] = array(
'#type' => 'radios',
'#title' => t('Default credit card transaction type'),
'#description' => t('The default will be used to process transactions during checkout.'),
'#options' => array(
COMMERCE_CREDIT_AUTH_CAPTURE => t('Authorisation and capture'),
COMMERCE_CREDIT_AUTH_ONLY => t('Authorisation only (requires manual or automated capture after checkout)'),
),
'#default_value' => $settings['transaction_type'],
);
$cur = array();
foreach (commerce_alphabank_redirect_available_currencies() as $nc => $c) {
$cur[$nc] = $nc;
}
$form['currency_code'] = array(
'#type' => 'radios',
'#title' => t('Default currency for all transactions'),
'#description' => t('The default currency that will be used to process transactions during checkout.'),
'#options' => $cur,
'#default_value' => $settings['currency_code'],
);
$form['send_payer_email'] = array(
'#type' => 'radios',
'#title' => t('Send payer email to the bank'),
'#options' => array('0' => t('No'), '1' => t('Yes')),
'#default_value' => $settings['send_payer_email'],
);
$form['order_description'] = array(
'#type' => 'textarea',
'#title' => t('Order description'),
'#description' => t('Order description to post data'),
'#required' => TRUE,
'#default_value' => $settings['order_description'],
);
$form['merchant_name'] = array(
'#type' => 'textfield',
'#title' => t('Merchant name'),
'#description' => t('The merchant name for transaction receipt'),
'#required' => TRUE,
'#default_value' => $settings['merchant_name'],
);
$form['cancelation_policy'] = array(
'#type' => 'textarea',
'#title' => t('Cancellation policy'),
'#description' => t('The cancellation policy of business'),
'#required' => TRUE,
'#default_value' => $settings['cancelation_policy'],
);
$form['payment_method_description'] = array(
'#type' => 'textarea',
'#title' => t('Payment method description'),
'#description' => t('The payment method description'),
'#required' => TRUE,
'#default_value' => $settings['payment_method_description'],
);
return $form;
}
/**
* Payment method callback: submit form.
*/
function commerce_alphabank_redirect_submit_form($payment_method, $pane_values, $checkout_pane, $order) {
$form = array();
if (!empty($payment_method['settings']['payment_method_description'])) {
$form['commerce_alphabank_redirect_description'] = array(
'#markup' => t($payment_method['settings']['payment_method_description'])
);
}
return $form;
}
/**
* Implements hook_redirect_form().
*/
function commerce_alphabank_redirect_redirect_form($form, &$form_state, $order, $payment_method) {
$settings = array();
// Return an error if the enabling action's settings haven't been configured.
if (empty($payment_method['settings']['mid'])) {
drupal_set_message(t('Alphabank Form Integration is not configured for use. Merchant has not been specified.'), 'error');
return array();
}
$wrapper = entity_metadata_wrapper('commerce_order', $order);
$total = commerce_line_items_total($wrapper->commerce_line_items);
$supported_currencies = commerce_alphabank_redirect_available_currencies();
$currencies = array_keys($supported_currencies);
if (!in_array($total['currency_code'], $currencies)) {
drupal_set_message(t('Current Site Currency is not supported by Alphabank proxy pay'), 'error');
return array();
}
$settings['currency_code'] = $supported_currencies[$total['currency_code']];
$settings['instance_id'] = $payment_method['instance_id'];
return commerce_alphabank_redirect_order_form($form, $form_state, $order, $total, $payment_method['settings'] + $settings);
}
/**
* Creates the Alphabank Form.
*/
function commerce_alphabank_redirect_order_form($form, &$form_state, $order, $total, $settings) {
// Ensure a default value for the payment_method setting.
// Probably, we don't have to..
$settings += array('payment_method' => '');
// Build the data array that will be translated into hidden form values.
$charge = number_format(floatval($total['amount']) / 100, 2, ',', '');
$current_datetime = date('Y-m-d H:i:s');
$current_timestamp = strtotime($current_datetime);
variable_set('alphabank_shared_secret_key', $settings['shared_secret_key']);
variable_set('alphabank_merchant_name', $settings['merchant_name']);
variable_set('alphabank_cancelation_policy', $settings['cancelation_policy']);
$data = array(
'mid' => $settings['mid'],
// Adding timestamp (10 chars) to order id because bank doesn't accept multiple posts with the same order id
'orderid' => $order->order_id . drupal_substr($current_timestamp, -10, 10),
'orderDesc' => drupal_substr($settings['order_description'], 0, 128),
'orderAmount' => $charge,
'currency' => $settings['currency_code'],
'payerEmail' => drupal_substr($order->mail, 0, 64),
'trType' => $settings['transaction_type'] == COMMERCE_CREDIT_AUTH_ONLY ? 2 : 1,
'confirmUrl' => url(AB_PAY_COMPLETED, array('absolute' => TRUE)),
'cancelUrl' => url(AB_PAY_ERROR, array('absolute' => TRUE)),
// TODO: Ask for installments from the user
/* 'Installments' => $settings['instance_id'], */
);
if ($settings['send_payer_email']== 0) {
unset($data['payerEmail']);
}
$digest_string = implode("", $data);
$digest_string .= $settings['shared_secret_key'];
$digest = base64_encode(sha1($digest_string, TRUE));
$data['digest'] = $digest;
$form['#action'] = $settings['post_url'];
foreach ($data as $name => $value) {
if (!empty($value)) {
$form[$name] = array('#type' => 'hidden', '#value' => $value);
}
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Proceed to Alphabank'),
);
return $form;
}
/**
* Supported currencies.
*/
function commerce_alphabank_redirect_available_currencies() {
/* 'GRD' => '300', /* Just in case */
return array('EUR' => '978', 'USD' => '840');
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function commerce_alphabank_redirect_form_commerce_checkout_form_alter(&$form, &$form_state) {
if (!empty($form['commerce_payment']['payment_method']['#options'])) {
foreach ($form['commerce_payment']['payment_method']['#options'] as $key => &$value) {
list($method_id, $rule_name) = explode('|', $key);
if ($method_id == 'commerce_alphabank_redirect') {
$alphabank_banks_icon = drupal_get_path('module', 'commerce_alphabank_redirect') . '/images/alphabank-banks-icon.png';
$value .= '<div class="commerce-alphabank-redirect-icons"><span class="label">' . t('Includes:') . '</span><img src="' . file_create_url($alphabank_banks_icon) . '" alt="" class="commerce-alphabank-redirect-icon" /></div>';
$form['commerce_payment']['payment_method']['#attached']['css'][] = drupal_get_path('module', 'commerce_alphabank_redirect') . '/css/commerce_alphabank_redirect.css';
break;
}
}
}
if (isset($form['#theme'][0]) && $form['#theme'][0] == 'commerce_checkout_form_complete') {
global $base_url;
$form['#attached']['css'][] = drupal_get_path('module', 'commerce_alphabank_redirect') . '/css/commerce_alphabank_redirect.css';
$completed_order_id = $form_state['order']->order_id;
$completed_order_load = commerce_order_load($completed_order_id);
$completed_order_payment_method = $form_state['order']->data['payment_method'];
list($method_id, $rule_name) = explode('|', $completed_order_payment_method);
$customer_profile_types = commerce_customer_profile_types();
$customer_profile_types = array_keys($customer_profile_types);
$billing_customer_profile_types = array();
$completed_order_line_item_ids = $completed_order_load->commerce_line_items[LANGUAGE_NONE];
$completed_order_line_item_titles = array();
foreach ($completed_order_line_item_ids as $completed_order_line_item_id) {
$commerce_line_item_load = commerce_line_item_load($completed_order_line_item_id['line_item_id']);
$commerce_line_item_product_load = isset($commerce_line_item_load->commerce_product[LANGUAGE_NONE][0]['product_id']) ? commerce_product_load($commerce_line_item_load->commerce_product[LANGUAGE_NONE][0]['product_id']) : '';
if (!empty($commerce_line_item_product_load->title)) {
$completed_order_line_item_titles[] = $commerce_line_item_product_load->title;
}
}
foreach ($customer_profile_types as $customer_profile_type) {
if (strpos($customer_profile_type, 'billing') !== FALSE) {
$billing_customer_profile_types[] = $customer_profile_type;
}
}
if (!empty($billing_customer_profile_types) && $method_id == 'commerce_alphabank_redirect') {
foreach ($billing_customer_profile_types as $billing_customer_profile_type) {
if (!empty($completed_order_load->{'commerce_customer_' . $billing_customer_profile_type})) {
$commerce_customer_profile_id = $completed_order_load->{'commerce_customer_' . $billing_customer_profile_type}[LANGUAGE_NONE][0]['profile_id'];
}
}
if (!empty($commerce_customer_profile_id)) {
$commerce_customer_profile_load = commerce_customer_profile_load($commerce_customer_profile_id);
$completed_order_payments = commerce_payment_transaction_load_multiple(array(), array('order_id' => $completed_order_id));
$completed_order_payment = !empty($completed_order_payments) ? array_shift($completed_order_payments) : '';
$completed_order_payment_payload = array_shift($completed_order_payment->payload);
$alphabank_merchant_name = variable_get("alphabank_merchant_name");
$alphabank_merchant_name_trim = trim($alphabank_merchant_name);
$alphabank_cancelation_policy = variable_get("alphabank_cancelation_policy");
$alphabank_cancelation_policy_trim = trim($alphabank_cancelation_policy);
$transaction_receipt_values = array(
array('label' => t('Purchaser name'), 'value' => !empty($commerce_customer_profile_load->commerce_customer_address[LANGUAGE_NONE][0]['name_line']) ? $commerce_customer_profile_load->commerce_customer_address[LANGUAGE_NONE][0]['name_line'] : ''),
array('label' => t('Order id'), 'value' => !empty($completed_order_payment_payload['orderid']) ? $completed_order_payment_payload['orderid'] : ''),
array('label' => t('Merchant name'), 'value' => !empty($alphabank_merchant_name_trim) ? $alphabank_merchant_name_trim : ''),
array('label' => t('Merchant on-line address'), 'value' => $base_url),
array('label' => t('Description of merchantise - services'), 'value' => !empty($completed_order_line_item_titles) ? implode(", ", $completed_order_line_item_titles) : ''),
array('label' => t('Transaction amount'), 'value' => !empty($completed_order_load->commerce_order_total[LANGUAGE_NONE][0]['amount']) ? commerce_currency_format($completed_order_load->commerce_order_total[LANGUAGE_NONE][0]['amount'], $completed_order_load->commerce_order_total[LANGUAGE_NONE][0]['currency_code']) : ''),
array('label' => t('Transaction date'), 'value' => !empty($completed_order_payment->created) ? date("d/m/Y - H:i:s", $completed_order_payment->created) : ''),
array('label' => t('Currency'), 'value' => !empty($completed_order_payment_payload['currency']) ? $completed_order_payment_payload['currency'] : ''),
array('label' => t('Authorization code'), 'value' => !empty($completed_order_payment_payload['txId']) ? $completed_order_payment_payload['txId'] : ''),
array('label' => t('Electronic commerce'), 'value' => 'Electronic commerce'),
array('label' => t('Cancellation policy'), 'value' => !empty($alphabank_cancelation_policy_trim) ? t($alphabank_cancelation_policy_trim) : ''),
);
$form['transaction_receipt'] = array(
'#type' => 'item',
'#markup' => theme('commerce_alphabank_redirect_transaction_receipt_output', $transaction_receipt_values),
'#weight' => 10,
);
}
}
}
}
function commerce_alphabank_redirect_theme() {
return array(
'commerce_alphabank_redirect_transaction_receipt_output' => array(
'variables' => array(),
),
);
}
function theme_commerce_alphabank_redirect_transaction_receipt_output($variables) {
if (!empty($variables['theme_hook_original'])) {
unset($variables['theme_hook_original']);
}
$output = NULL;
if (!empty($variables)) {
$header = array(
array('data' => t('Transaction receipt'), 'colspan' => 2),
);
$rows = array();
foreach ($variables as $variable) {
$rows[] = array(
array('data' => $variable['label'], 'class' => 'title'),
array('data' => $variable['value'], 'class' => 'value'),
);
}
$output = '<div id="transaction-receipt" class="transaction-receipt">';
$output .= theme('table', array(
'header' => $header,
'rows' => $rows,
)
);
$output .= '<div class="transaction-receipt-actions">';
$output .= l(t('Print transaction receipt'), '', array(
'fragment' => 'edit-transaction-receipt',
'external' => TRUE,
'attributes' => array(
'onclick' => 'window.print();',
),
)
);
$output .= '</div></div>';
}
return $output;
}
......@@ -79,7 +79,7 @@ function commerce_alphabank_redirect_complete() {
$transaction->instance_id = $delta_pay_id;
$transaction->amount = floatval($payment_amount) * 100;
$transaction->currency_code = $payment_currency_code;
$transaction->payload[REQUEST_TIME] = $data;
$transaction->payload[\Drupal::time()->getRequestTime()] = $data;
$transaction->status = COMMERCE_PAYMENT_STATUS_SUCCESS;
$transaction->remote_id = $delta_pay_id;
$transaction->remote_status = $payment_status;
......@@ -113,7 +113,7 @@ function commerce_alphabank_redirect_error() {
$transaction = commerce_payment_transaction_new('commerce_alphabank_redirect', $order_id);
$transaction->instance_id = -1;
$transaction->payload[REQUEST_TIME] = $data;
$transaction->payload[\Drupal::time()->getRequestTime()] = $data;
$transaction->status = COMMERCE_PAYMENT_STATUS_FAILURE;
$transaction->remote_id = $delta_pay_id;
$transaction->remote_status = $payment_status;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment