/**
* Generate azericard button link
**/
public function generate_azericard_form($order_id){
$admin_settings = $this->get_admin_settings();
$order = new WC_Order( $order_id );
$amount = $order->total;
$currency = $order->currency;
$description = 'Order #'.$order_id;
$db_row['AMOUNT'] = $amount; // 2.5
$db_row['CURRENCY'] = $currency;
$db_row['ORDER'] = $this->genOrderID_az($order_id);
// These fields will be always static
$db_row['DESC'] = $description;
$db_row['MERCH_NAME'] = $this->merch_name;
$db_row['MERCH_URL'] = $this->merch_url;
$db_row['TERMINAL'] = $admin_settings['terminal']; // That is your personal ID in payment system
$db_row['EMAIL'] = $this->email;
$db_row['TRTYPE'] = '1'; // That is the type of operation, 0 - Authorization
$db_row['COUNTRY'] = 'AZ';
$db_row['MERCH_GMT'] = '+4';
$db_row['BACKREF'] = $this->backref;
// These fields are generated automatically every request
$oper_time = gmdate("YmdHis"); // Date and time UTC
$nonce = substr(md5(rand()),0,16); // Random data
// Creating form hidden fields
$form .= "
";
// ------------------------------------------------
// Making P_SIGN (MAC) - Checksum of request
// All following fields must be equal with hidden fields above
$to_sign = "".strlen($db_row['AMOUNT']).$db_row['AMOUNT']
.strlen($db_row['CURRENCY']).$db_row['CURRENCY']
.strlen($db_row['ORDER']).$db_row['ORDER']
.strlen($db_row['DESC']).$db_row['DESC']
.strlen($db_row['MERCH_NAME']).$db_row['MERCH_NAME']
.strlen($db_row['MERCH_URL']).$db_row['MERCH_URL']."-"
.strlen($db_row['TERMINAL']).$db_row['TERMINAL']
.strlen($db_row['EMAIL']).$db_row['EMAIL']
.strlen($db_row['TRTYPE']).$db_row['TRTYPE']
.strlen($db_row['COUNTRY']).$db_row['COUNTRY']
.strlen($db_row['MERCH_GMT']).$db_row['MERCH_GMT']
.strlen($oper_time).$oper_time
.strlen($nonce).$nonce
.strlen($db_row['BACKREF']).$db_row['BACKREF'];
$p_sign = hash_hmac('sha1', $to_sign, $this->hex2bin_az($admin_settings['key_for_sign']));
$form .= "".PHP_EOL;
return '
' . $form . '
';
}
/**
* Process the payment and return the result
**/
public function process_payment($order_id){
$order = wc_get_order( $order_id );
// Mark as on-hold (we're awaiting the cheque)
$order->update_status( 'on-hold', _x( 'Awaiting check payment', 'Check payment method', 'azericard' ) );
// Reduce stock levels
wc_reduce_stock_levels( $order_id );
// Remove cart
WC()->cart->empty_cart();
// Return thankyou redirect
return array(
'result' => 'success',
'redirect' => $this->get_return_url( $order ),
);
}
public function checkCallbackData($data) {
$admin_settings = $this->get_admin_settings();
$p_sign_post = $data['P_SIGN'];
$to_sign =
strlen($data['TERMINAL']).$data['TERMINAL']
.strlen($data['TRTYPE']).$data['TRTYPE']
.strlen($data['ORDER']).$data['ORDER']
.strlen($data['AMOUNT']).$data['AMOUNT']
.strlen($data['CURRENCY']).$data['CURRENCY']
.strlen($data['ACTION']).$data['ACTION']
.strlen($data['RC']).$data['RC']
.strlen($data['APPROVAL']).$data['APPROVAL']
.strlen($data['RRN']).$data['RRN']
.strlen($data['INT_REF']).$data['INT_REF']
.strlen($data['TIMESTAMP']).$data['TIMESTAMP']
.strlen($data['NONCE']).$data['NONCE'];
$p_sign = hash_hmac('sha1', $to_sign, $this->hex2bin_az($admin_settings['key_for_sign']));
return (strtoupper($p_sign) == $p_sign_post);
}
Вопрос задан
более трёх лет назад
58 просмотров