Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Payment Addon Development Rate Topic   - - - - -

 
  • huyvu
  • Newbie
  • Trial users
  • Join Date: 22-Jun 20
  • 9 posts

Posted 22 June 2020 - 05:18 PM #1

Hi,

 

Sorry I can't post this topic to Developers' Corner.

 

I'm going to code an e-wallet payment gateway for my own multi-vendor page by myself. Are there any docs, workflows or tutorials more detail than the official one?

 

Thank you so much!



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 20775 posts

Posted 23 June 2020 - 05:19 AM #2

Did you check the following article?

 

https://docs.cs-cart...ssor_addon.html


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      Multi-Vendor Ultimate       USD 7500 (6000)

 
  • huyvu
  • Newbie
  • Trial users
  • Join Date: 22-Jun 20
  • 9 posts

Posted 23 June 2020 - 08:02 AM #3

Did you check the following article?

 

https://docs.cs-cart...ssor_addon.html

Yes, I did and read code of another addons too. I think i should get to work before asking. Thanks



 
  • huyvu
  • Newbie
  • Trial users
  • Join Date: 22-Jun 20
  • 9 posts

Posted 06 July 2020 - 06:21 PM #4

Did you check the following article?

 

https://docs.cs-cart...ssor_addon.html

Hi,

 

I use fn_create_payment_form to submit a request but get problem with parsing body. Here my code:

use Tygh\Registry;

defined('BOOTSTRAP') or die('Access denied');

// Here are two different contexts for running the script.
if (defined('PAYMENT_NOTIFICATION')) {

    fn_print_r("Processing the answer");

} else {

    $secretKey = $processor_data['processor_params']['secret_key'];
    $endpoint = "https://test-payment.mm.vn/gw_payment/transactionProcessor";

    $partnerCode = $processor_data['processor_params']['partner_code'];
    $accessKey = $processor_data['processor_params']['access_key'];
    $orderId = $order_id;
    $orderInfo = "Test";
    $amount = $order_info['total'] * 23000;
    $returnUrl = fn_url("payment_notification.invoice?payment=mm&order_id=$order_id", AREA, 'https');
    $notifyUrl = fn_url("payment_notification.notify?payment=mm&order_id=$order_id", AREA, 'https');

    $requestId = time() . "";
    $requestType = "captureMMWallet";
    $extraData = "merchantName=MM_Partner";

    $rawHash = "partnerCode=" . $partnerCode . "&accessKey=" . $accessKey . "&requestId=" . $requestId . "&amount=" . $amount . "&orderId=" . $orderId . "&orderInfo=" . $orderInfo . "&returnUrl=" . $returnUrl . "&notifyUrl=" . $notifyUrl . "&extraData=" . $extraData;

    $signature = hash_hmac("sha256", $rawHash, $secretKey);
    $post_data = array(
        'partnerCode' => $partnerCode,
        'accessKey' => $accessKey,
        'requestId' => $requestId,
        'amount' => $amount,
        'orderId' => $orderId,
        'orderInfo' => $orderInfo,
        'returnUrl' => $returnUrl,
        'notifyUrl' => $notifyUrl,
        'extraData' => $extraData,
        'requestType' => $requestType,
        'signature' => $signature
    );

    //fn_print_r($post_data);
    //fn_print_r($signature);
    fn_create_payment_form($endpoint, $post_data, 'MM');

    exit;
}

My error

{
    "request": {
        "data": "...",
        "timeout": 90,
        "headers": {
            "headers": {
                "sec-fetch-mode": "navigate",
                "content-length": "508",
                "referer": "http://xxx.vn/index.php?dispatch=checkout.place_order",
                "sec-fetch-site": "cross-site",
                "x-forwarded-proto": "http",
                "accept-language": "en-US,en;q=0.9",
                "cookie": "JSESSIONID=E1EDEE9D138CAD48510C482A2A498F76",
                "origin": "http://xxx.vn",
                "x-forwarded-port": "80",
                "x-forwarded-for": "xxx.xxx.xxx.xxx, xxx.xx.x.xx",
                "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
                "x-real-ip": "xxx.xx.x.xx",
                "x-forwarded-host": "test-payment.momo.vn",
                "host": "test-payment.momo.vn",
                "x-powered-by": "momo.vn",
                "upgrade-insecure-requests": "1",
                "connection": "keep-alive",
                "content-type": "application/x-www-form-urlencoded",
                "x-forwarded-by": "xxx.xx.x.xx:443",
                "cache-control": "max-age=0",
                "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36 OPR/68.0.3618.173",
                "sec-fetch-dest": "document"
            }
        }
    },
    "errorCode": 59,
    "message": "Error parsing body to Json object. Accepted Content-Type: application/json; charset=UTF-8. Check request headers and body",
    "localMessage": "Yêu cầu không hợp lệ"
}

Please help. Thanks so much.



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 20775 posts

Posted 07 July 2020 - 05:40 AM #5

Check documentation for developers. Looks like you should send body in json format, not separate fields (partnerCode, accessKey, etc)


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      Multi-Vendor Ultimate       USD 7500 (6000)

 
  • huyvu
  • Newbie
  • Trial users
  • Join Date: 22-Jun 20
  • 9 posts

Posted 07 July 2020 - 09:35 AM #6

Check documentation for developers. Looks like you should send body in json format, not separate fields (partnerCode, accessKey, etc)

Could I use fn_create_payment_form to send Json or I need to override it? Or use another function? My payment processor is "callback=N". Thanks



 
  • huyvu
  • Newbie
  • Trial users
  • Join Date: 22-Jun 20
  • 9 posts

Posted 07 July 2020 - 11:13 AM #7

I'm using cUrl instead of fn_create_payment_form. Is it good? Thanks

$post_data = json_encode($data);

$ch = curl_init($endpoint);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// for localhost
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

$result = curl_exec($ch);
curl_close($ch);

$arrayResult = json_decode($result, true);

header('Content-type: text/html; charset=utf-8');
header('Location: ' . $arrayResult['payUrl']);

exit;


 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 20775 posts

Posted 07 July 2020 - 02:00 PM #8

It is better to use Http:get or Http::get default methods. Some integrated payment systems use it


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      Multi-Vendor Ultimate       USD 7500 (6000)

 
  • huyvu
  • Newbie
  • Trial users
  • Join Date: 22-Jun 20
  • 9 posts

Posted 16 July 2020 - 06:16 AM #9

Hi eComLabs,

 

I get "404 Page not found" with the return url

http://sivin-7f251c0d.localhost.run/index.php?dispatch=payment_notification.invoice&payment=Momo&order_id=101&partnerCode=...

My payment_notification code:

if (defined('PAYMENT_NOTIFICATION')) {

    if (!fn_check_payment_script(MOMO_PROCESSOR_SCRIPT, $order_id)) {
        return array(CONTROLLER_STATUS_DENIED);
    }

    $order_id = $_REQUEST['order_id'];
    $pp_response = fn_momo_response_processing($_REQUEST, $processor_data['processor_params']['secret_key']);
        
    if ($mode == 'notify') {

        fn_change_order_status($order_id, $pp_response["order_status"], '', true);
        exit();

    } elseif ($mode == 'invoice') {

        fn_finish_payment($order_id, $pp_response, false);
        fn_order_placement_routines('route', $order_id);
        exit();
    }

}

Thanks for your help :wub:



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 20775 posts

Posted 16 July 2020 - 01:55 PM #10

If your payment script is called my_script.php, URL should contain the following parameter

 

...&payment=my_script&...


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      Multi-Vendor Ultimate       USD 7500 (6000)

 
  • huyvu
  • Newbie
  • Trial users
  • Join Date: 22-Jun 20
  • 9 posts

Posted 17 July 2020 - 06:09 AM #11

If your payment script is called my_script.php, URL should contain the following parameter

 

...&payment=my_script&...

I already changed payment to my script ...&payment=momo_processor&... but still doesn't work. Please see the attachment. Thanks

Attached Thumbnails

  • screenshot.png


 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 20775 posts

Posted 17 July 2020 - 01:03 PM #12

then replace

if (!fn_check_payment_script(MOMO_PROCESSOR_SCRIPT, $order_id)) {

with

if (!fn_check_payment_script('momo_processor.php', $_REQUEST['order_id'])) {

GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      Multi-Vendor Ultimate       USD 7500 (6000)

 
  • huyvu
  • Newbie
  • Trial users
  • Join Date: 22-Jun 20
  • 9 posts

Posted 17 July 2020 - 06:04 PM #13

 

then replace

if (!fn_check_payment_script(MOMO_PROCESSOR_SCRIPT, $order_id)) {

with

if (!fn_check_payment_script('momo_processor.php', $_REQUEST['order_id'])) {

 

Thank you so much. It works. I passed an empty order_id.

 

There are new problem:

- I can't get $processor_data when PAYMENT_NOTIFICATION defined.

- fn_order_placement_routines('route', $order_id) doesn't clear cart and not redirect to order completed page but come back to checkout page.



 
  • huyvu
  • Newbie
  • Trial users
  • Join Date: 22-Jun 20
  • 9 posts

Posted 17 July 2020 - 06:39 PM #14

Thank you so much. It works. I passed an empty order_id.

 

There are new problem:

- I can't get $processor_data when PAYMENT_NOTIFICATION defined.

- fn_order_placement_routines('route', $order_id) doesn't clear cart and not redirect to order completed page but come back to checkout page.

My bad, fn_order_placement_routines('route', $order_id) work when $pp_response['order_status'] = 'P'



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 20775 posts

Posted 20 July 2020 - 05:33 AM #15

There are new problem:

- I can't get $processor_data when PAYMENT_NOTIFICATION defined.

 

$order_info = fn_get_order_info($_REQUEST['order_id']);
$processor_data = fn_get_processor_data($order_info['payment_id']);

GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      Multi-Vendor Ultimate       USD 7500 (6000)