How to integrate 2c2p payment api in drupal module?

2.2k views Asked by At

I am implementing a 2c2p payment api in custom drupal module.The error is showing like

9002 : Payment authorization failed.

in the url

https://demo2.2c2p.com/2C2PFrontEnd/RedirectV3/payment/Error?result=9002&result_desc=Payment%20authorization%20failed.

and here is my a few code to submit.

$controller_data = $payment->method->controller_data;

// Get settings from controller data.
$merchant_id = $controller_data['msp_2c2p_id'];
$secret_key = $controller_data['msp_2c2p_secret'];
$url = $controller_data['msp_2c2p_mode'];
$version = $controller_data['msp_2c2p_version'];
$version = '6.7';
$payment_description = 'test payment';
$order_id = '00000000010000091203';
$invoice_no = $payment->pid;
$currency = '840'; //840 = USD, 104 = MMK
$customer_email = '[email protected]';
$pay_category_id = ''; // (Optional) Merchant’s predefined payment category code for reporting purpose. Merchant can manage predefined codes from the my.2c2p interface, section merchant report. ACCOUNT => Options => Predefined References Use PAYCATEGORYID value from “Ref Code” column to show “Reference Name” in the homepage sales volume graph.
$promotion = 'PROMO_VC';
$user_defined_1 = 'test1';
$user_defined_2 = 'test2';
$user_defined_3 = 'test3';
$user_defined_4 = 'test4';
$user_defined_5 = 'test5';
$result_url_1 = url(MSP_2C2P_PAYMENT_RETURN_PATH
          . '/' . $payment->pid, array('absolute' => TRUE));
$result_url_2=url(MSP_2C2P_PAYMENT_RETURN_PATH
          . '/' . $payment->pid, array('absolute' => TRUE));
$enable_store_card = 'N';
$stored_card_unique_id = '';//(Optional) Mandatory when payment is made by stored card
$pan_masked = ''; 
$request_3ds = 'Y';               //(Optional)  Y – Do 3ds (default) F – Force 3ds (Only ECI 02 / 05 are accepted) N - Do not do 3ds
$recurring = 'N';                 //(Optional)  N – Not recurring (default) Y – Recurring transaction
$order_prefix = '';             //Note: if it is recurring payment, it is mandatory.
$recurring_amount = '000000199900';   //Example: THB (764) 
$allow_accumulate  = 'N';         //N – Not allow Y – Allow accumulate Note: if it is recurring payment, it is mandatory.
$max_accumulate_amount = '000000199900';//Note: if it is recurring payment, it is mandatory.
$recurring_interval = '';       //Note: If it is recurring payment, it is mandatory if charge_on_date is blank.
$recurring_count = '';          //Note: If it is recurring payment, it is mandatory
$charge_next_date = '';         //Note: If it is recurring payment, it is mandatory
$charge_on_date = '';           //Note: If it is recurring payment, either charge_on_date or recurring_interval is mandatory
$payment_option = 'A';            //By default, all available options (A) will be shown.
$ipp_interest_type = 'A';         //By default, all available options (A) will be shown
$payment_expiry = '';           //By default, 1-2-3 system will set the expiry according to merchant configuration.
$default_lang = 'en';             //ja – Japanese th – Thailand en – English (default)
$statement_descriptor = 'A23';     //Only allows alphanumeric in latin character

 /**
 * Calculate amount to pay.
 */
$amount = 0;
foreach ($payment->line_items as $line_item) {
  $amount += (1 + $line_item->tax_rate) * $line_item->amount
          * $line_item->quantity;
}

$payment_data = array(
  //'amount' => $amount,
  'amount' => '000000000100',
  'description' => $payment->description,
);
$amount = $payment_data['amount'];

and

$strSignatureString = $version . $merchant_id . $payment_description . $order_id . $invoice_no . $currency . $amount . $customer_email . $pay_category_id . $promotion . $user_defined_1 . $user_defined_2 . $user_defined_3 . $user_defined_4 . $user_defined_5 . $result_url_1 . $result_url_2 . $enable_store_card . $stored_card_unique_id . $pan_masked . $request_3ds . $recurring . $order_prefix . $recurring_amount . $allow_accumulate . $max_accumulate_amount . $recurring_interval . $recurring_count . $charge_next_date . $charge_on_date . $payment_option . $ipp_interest_type . $payment_expiry . $default_lang . $statement_descriptor;

$data = array(
  'version' => $version,
  'merchant_id' => $merchant_id,
  'payment_description' =>$payment_description,
  'order_id' => $order_id,
  'invoice_no' => $invoice_no,
  'currency' => $currency,
  'amount' => $amount,
  'customer_email' => $customer_email,
  'pay_category_id' => $pay_category_id,
  'promotion' => $promotion,
  'user_defined_1' => $user_defined_1,
  'user_defined_2' => $user_defined_2,
  'user_defined_3' => $user_defined_3,
  'user_defined_4' => $user_defined_4,
  'user_defined_5' => $user_defined_5,
  'result_url_1' => $result_url_1,
  'result_url_2' => $result_url_2,
  'enable_store_card' => $enable_store_card,
  'stored_card_unique_id' => $stored_card_unique_id,
  'pan_masked' => $pan_masked,
  'request_3ds' => $request_3ds,
  'recurring' => $recurring,
  'order_prefix' => $order_prefix,
  'recurring_amount' => $recurring_amount,
  'allow_accumulate' => $allow_accumulate,
  'max_accumulate_amount' => $max_accumulate_amount,
  'recurring_interval' => $recurring_interval,
  'recurring_count' => $recurring_count,
  'charge_next_date' => $charge_next_date,
  'charge_on_date' => $charge_on_date,
  'payment_option' => $payment_option,
  'ipp_interest_type' => $ipp_interest_type,
  'payment_expiry' => $payment_expiry,
  'default_lang' => $default_lang,
  'statement_descriptor' => $statement_descriptor,
  'hash_value' => strtoupper(hash_hmac('sha1', $strSignatureString, $secret_key, false)),
);



$form['#action'] = $url;
//$form['#action'] = 'http://msp_2c2p.dd:8083/2c2ptest.php';
foreach($data as $name => $value) {
  if (!empty($value)) {
    $form[$name] = array('#type' => 'hidden', '#value' => $value);
  }
}
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
  '#type' => 'submit',
  '#value' => t('Pay with 2c2p'),
);

return $form;

}

Is there any wrong in my codes?We are following these link 2c2p developer doc and doc2 Thanks in advance.

1

There are 1 answers

2
saturngod On

9002 is the hash value mismatch.

https://developer.2c2p.com/docs/codes-dir

Please check the $strSignatureString and $secret_key.

Please check at https://developer.2c2p.com/docs/payment-request-dir