PayPal IPN 适用于单个购物车项目,但不适用于多个购物车项目 [英] PayPal IPN working for single cart items but not multiple cart items

查看:72
本文介绍了PayPal IPN 适用于单个购物车项目,但不适用于多个购物车项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Google 表格中找到了这个 Paypal IPN 代码,它确实适用于我购物车中的单个商品,但不适用于任何多购物车商品.我不知道我在做什么,我希望稍微编辑此代码以使其适用于多个购物车项目.任何帮助将非常感激.谢谢!

I found this Paypal IPN code with Google Sheets and it does work for single items in my cart, but not for any multi cart items. I have no idea what I'm doing and I'm hoping to edit this code a little to get it to work for multiple cart items. Any help would be much appreciated. Thanks!

 function doPost(e) {

  var rowData = [];

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet()

  rowData.push(new Date(e.parameter.payment_date));
    rowData.push(e.parameter.payment_type);
    rowData.push(e.parameter.payment_status);    
    rowData.push(e.parameter.payer_email);
    rowData.push(e.parameter.item_name1);
    rowData.push(e.parameter.item_number1);
    rowData.push(e.parameter.quantity);
    rowData.push(e.parameter.first_name);
    rowData.push(e.parameter.last_name);
        rowData.push(e.parameter.address_street);
        rowData.push(e.parameter.address_city);
        rowData.push(e.parameter.address_state);
        rowData.push(e.parameter.address_zip);
  
  sheet.appendRow(rowData);
}

这是我收到的 IPN 消息,减去编辑我的一些个人信息...

Here is the IPN message I get back minus editing some of my personal information...

mc_gross=11.97&protection_eligibility=Eligible&address_status=confirmed&item_number1=&item_number2=&payer_id=HJXtestY&item_number3=&address_street=testS.test Road&payment_date=19:07:58 May 12, 2021 PDT&payment_status=Completed&charset=windows-1252&address_zip=test&first_name=Brett&mc_fee=0.65&address_country_code_notBrett&=3.9&custom=/xotio-media/2019/2019-07-13-Tushar-Crusher-Photos&payer_status=verified&business=xotestail.com&address_country=美国&num_cart_items=3&address_verify_sign=test-test.test-cfj7Q1YCC6WrT&payer_email=testl.com&txn_id=0BFtest11545&payment_type=instant&payer_business_name=Brett testphy - detestoto&last_name=testr&address_state=testl.com&txn_id=0BFtest11545&payment_type=instant&payer_business_name=Brett testphy - detestoto&last_name=testr&address_state=testl.com&txn_id=0BFtest11545&payment_type=10rusho/Top-Col-de-Crush/19-TC-111644-190713-BP3_3724.jpg :: 下载原版&receiver_email=testil.com&item_name2=2019-07-13-Tushar-Crusher-Photos/Top-Col-de-Crush/19-TC-111645-190713-BP3_3725.jpg :: 下载原件&payment_fee=0.65&item_name3=2019-07-13-Tushar-Crusher-Photos/Top-Col-de-Crush/19-TC-111646-190713-BP3_3726.jpg :: 下载原版&shipping_discount=0.00&quantity1=1&insurance_amount=0.00&quantity2=1&receiver_id=3SKEBUJZ&t&quantity=0.00&quantity1=0.00&mc_gross_1=3.99&mc_currency=USD&mc_gross_2=3.99&mc_gross_3=3.99&residence_country=US&shipping_method=Default&transaction_subject=&transaction_subject_9s_gross_2=3.99&mc_gross_3=3.99&shipping_method=Default&transaction_subject_9s_gross_2=3.9s

mc_gross=11.97&protection_eligibility=Eligible&address_status=confirmed&item_number1=&item_number2=&payer_id=HJXtestY&item_number3=&address_street=testS. test Road&payment_date=19:07:58 May 12, 2021 PDT&payment_status=Completed&charset=windows-1252&address_zip=test&first_name=Brett&mc_fee=0.65&address_country_code=US&address_name=Brett - detestto&notify_version=3.9&custom=/xotio-media/2019/2019-07-13-Tushar-Crusher-Photos&payer_status=verified&business=xotestail.com&address_country=United States&num_cart_items=3&address_city=test&verify_sign=test-test.test-cfj7Q1YCC6WrT&payer_email=testl.com&txn_id=0BFtest11545&payment_type=instant&payer_business_name=Brett testphy - detestoto&last_name=testr&address_state=UT&item_name1=2019-07-13-Tushar-Crusher-Photos/Top-Col-de-Crush/19-TC-111644-190713-BP3_3724.jpg :: Download Original&receiver_email=testil.com&item_name2=2019-07-13-Tushar-Crusher-Photos/Top-Col-de-Crush/19-TC-111645-190713-BP3_3725.jpg :: Download Original&payment_fee=0.65&item_name3=2019-07-13-Tushar-Crusher-Photos/Top-Col-de-Crush/19-TC-111646-190713-BP3_3726.jpg :: Download Original&shipping_discount=0.00&quantity1=1&insurance_amount=0.00&quantity2=1&receiver_id=3SKEBUJZCV7AS&quantity3=1&txn_type=cart&discount=0.00&mc_gross_1=3.99&mc_currency=USD&mc_gross_2=3.99&mc_gross_3=3.99&residence_country=US&shipping_method=Default&transaction_subject=&payment_gross=11.97&ipn_track_id=e0b32d1a10a85

推荐答案

当有多个项目时,记录您收到的文本,并相应地更改代码以进行解析.

Log the text of what you receive when there are multiple items, and change the code accordingly to parse that.

您还可以通过以下方式查看接收方帐户的 IPN 历史记录:

You can also review the IPN history of the receiver account, via:

沙盒:https://www.sandbox.paypal.com/webscr?cmd=_display-ipns-history

类似于:

    rowData.push(e.parameter.payment_type);
    rowData.push(e.parameter.payment_status);    
    rowData.push(e.parameter.payer_email);
    rowData.push(e.parameter.first_name);
    rowData.push(e.parameter.last_name);
    rowData.push(e.parameter.address_street);
    rowData.push(e.parameter.address_city);
    rowData.push(e.parameter.address_state);
    rowData.push(e.parameter.address_zip);

    e.parameter.quantity1 = e.parameter.quantity1 || e.parameter.quantity || '';
    let i = 1;
    while(e.parameter['item_name'+i]) {
        rowData.push(e.parameter['item_name'+i]);
        rowData.push(e.parameter['item_number'+i]);
        rowData.push(e.parameter['quantity'+i]);
        i++;
    }


更好的是,停止使用像 IPN 这样古老的东西,改用当前的 v2/checkout/orders 集成.在您的服务器上创建两条路由,一条用于创建订单",一条用于捕获订单",此处记录.这些路由应该只返回 JSON 数据(没有 HTML 或文本).后者应该(成功时)在返回之前将购物车项目和付款详细信息存储在您的数据库(或者,呃,电子表格)中 - 特别是 purchase_units[0].payments.captures[0].id,PayPal 交易 ID.


Better yet, stop using something ancient like IPN and change to a current v2/checkout/orders integration. Make two routes on your server, one for 'Create Order' and one for 'Capture Order', documented here. These routes should return only JSON data (no HTML or text). The latter one should (on success) store the cart items and payment details in your database (or, uhm, spreadsheet) before it does the return -- particularly purchase_units[0].payments.captures[0].id, the PayPal transaction ID.

将这两条路线与以下审批流程配对:https://developer.paypal.com/demo/checkout/#/pattern/server

Pair those two routes with the following approval flow: https://developer.paypal.com/demo/checkout/#/pattern/server

这篇关于PayPal IPN 适用于单个购物车项目,但不适用于多个购物车项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆