title: How to integrate 2c2p payment api in drupal module?
body: <p>I am implementing a 2c2p payment api in custom drupal module.The error is showing like </p>
  
  <blockquote>
    <p>9002 : Payment authorization failed.</p>
  </blockquote>
  
  <p>in the url</p>
  
  <blockquote>
    <p><a href="https://demo2.2c2p.com/2C2PFrontEnd/RedirectV3/payment/Error?result=9002&amp;result_desc=Payment%20authorization%20failed" rel="nofollow noreferrer">https://demo2.2c2p.com/2C2PFrontEnd/RedirectV3/payment/Error?result=9002&amp;result_desc=Payment%20authorization%20failed</a>.</p>
  </blockquote>
  
  <p>and here is my a few code to submit.</p>
  
  <pre><code>$controller_data = $payment-&gt;method-&gt;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-&gt;pid;
  $currency = '840'; //840 = USD, 104 = MMK
  $customer_email = 'thanhtut@mspiral.com';
  $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 =&gt; Options =&gt; 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-&gt;pid, array('absolute' =&gt; TRUE));
  $result_url_2=url(MSP_2C2P_PAYMENT_RETURN_PATH
            . '/' . $payment-&gt;pid, array('absolute' =&gt; 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-&gt;line_items as $line_item) {
    $amount += (1 + $line_item-&gt;tax_rate) * $line_item-&gt;amount
            * $line_item-&gt;quantity;
  }
  
  $payment_data = array(
    //'amount' =&gt; $amount,
    'amount' =&gt; '000000000100',
    'description' =&gt; $payment-&gt;description,
  );
  $amount = $payment_data['amount'];
  </code></pre>
  
  <p>and </p>
  
  <pre><code>$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' =&gt; $version,
    'merchant_id' =&gt; $merchant_id,
    'payment_description' =&gt;$payment_description,
    'order_id' =&gt; $order_id,
    'invoice_no' =&gt; $invoice_no,
    'currency' =&gt; $currency,
    'amount' =&gt; $amount,
    'customer_email' =&gt; $customer_email,
    'pay_category_id' =&gt; $pay_category_id,
    'promotion' =&gt; $promotion,
    'user_defined_1' =&gt; $user_defined_1,
    'user_defined_2' =&gt; $user_defined_2,
    'user_defined_3' =&gt; $user_defined_3,
    'user_defined_4' =&gt; $user_defined_4,
    'user_defined_5' =&gt; $user_defined_5,
    'result_url_1' =&gt; $result_url_1,
    'result_url_2' =&gt; $result_url_2,
    'enable_store_card' =&gt; $enable_store_card,
    'stored_card_unique_id' =&gt; $stored_card_unique_id,
    'pan_masked' =&gt; $pan_masked,
    'request_3ds' =&gt; $request_3ds,
    'recurring' =&gt; $recurring,
    'order_prefix' =&gt; $order_prefix,
    'recurring_amount' =&gt; $recurring_amount,
    'allow_accumulate' =&gt; $allow_accumulate,
    'max_accumulate_amount' =&gt; $max_accumulate_amount,
    'recurring_interval' =&gt; $recurring_interval,
    'recurring_count' =&gt; $recurring_count,
    'charge_next_date' =&gt; $charge_next_date,
    'charge_on_date' =&gt; $charge_on_date,
    'payment_option' =&gt; $payment_option,
    'ipp_interest_type' =&gt; $ipp_interest_type,
    'payment_expiry' =&gt; $payment_expiry,
    'default_lang' =&gt; $default_lang,
    'statement_descriptor' =&gt; $statement_descriptor,
    'hash_value' =&gt; strtoupper(hash_hmac('sha1', $strSignatureString, $secret_key, false)),
  );
  
  
  
  $form['#action'] = $url;
  //$form['#action'] = 'http://msp_2c2p.dd:8083/2c2ptest.php';
  foreach($data as $name =&gt; $value) {
    if (!empty($value)) {
      $form[$name] = array('#type' =&gt; 'hidden', '#value' =&gt; $value);
    }
  }
  $form['actions'] = array('#type' =&gt; 'actions');
  $form['actions']['submit'] = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; t('Pay with 2c2p'),
  );
  
  return $form;
  </code></pre>
  
  <p>}</p>
  
  <p>Is there any wrong in my codes?We are following these link
  <a href="https://developers-2c2p-com.readme.io/v1.0/docs/redirect-variables" rel="nofollow noreferrer">2c2p developer doc</a> and <a href="https://developer.2c2p.com/docs/sandbox" rel="nofollow noreferrer">doc2</a>
  Thanks in advance.</p>