如何使用PHP使用PayPal IPN遍历项目变量?

时间:2018-10-25 02:47:10

标签: php paypal paypal-ipn

由于不赞成使用变量“ num_cart_items”,如何遍历变量“ item_name”以获取项目总数? PayPal IPN为第一个项目返回“ item_name”,然后为随后的项目返回“ item_name1”,“ item_name2”等。我想将item_name存储为单个或多个。我该怎么做呢?我通常会使用“ array.count”的“ for”语句遍历数组,但是由于“ num_cart_items”不再可用,因此我不确定如何实现。

这是当前PayPal IPN响应的样子:

{
        "payment_type": "instant",
        "payment_date": "18:11:12 Oct 23, 2018 PDT",
        "payment_status": "Completed",
        "payer_status": "verified",
        "first_name": "John",
        "last_name": "Smith",
        "payer_email": "buyer@xyz.com",
        "payer_id": "TESTBUYERID01",
        "address_name": "John Smith",
        "address_country": "United States",
        "address_country_code": "US",
        "address_zip": "95131",
        "address_state": "CA",
        "address_city": "San Jose",
        "address_street": "123 any street",
        "business": "seller@xyz.com",
        "receiver_email": "seller@xyz.com",
        "receiver_id": "seller@xyz.com",
        "residence_country": "US",
        "item_name": "some item",
        "item_name1": "something",
        "item_number": "AKZ-1978",
        "item_number1": "AK-1234",
        "quantity": "1",
        "shipping": "3.04",
        "tax": "2.02",
        "mc_currency": "USD",
        "mc_fee": "0.44",
        "mc_gross": "12.34",
        "mc_gross_1": "12.34",
        "mc_handling": "2.06",
        "mc_handling1": "1.67",
        "mc_shipping": "3.02",
        "mc_shipping1": "1.02",
        "txn_type": "cart",
        "txn_id": "899327589",
        "notify_version": "2.4",
        "custom": "xyz123",
        "invoice": "abc1234",
        "test_ipn": "1",
        "verify_sign": "xxxxxxxxxxxxxxx"
    }

0 个答案:

没有答案