通过cURL付款将自定义变量添加到paypal IPN

时间:2014-01-29 21:19:56

标签: php codeigniter curl paypal

我的问题:设置将在IPN上返回的paypal变量。

所以背景: 我正在使用CodeIgniter,我正在使用我发现的预制在线库来处理整个paypal事情。图书馆负担得起,工作得很好。 [这是我正在使用的图书馆] [1]

据我所知,图书馆使用XML格式向paypal发送一个cURL请求,其中包含所有需要的信息,基本上如paypal本身所示[here] [2]

这个库文档很少,我不知道如何采取下一步。

下一步是,将数据添加到将显示在IPN上的cURL请求中。

确切地说;我会找到一种方法来添加数据,我更感兴趣的是它应该如何看待最终。

这是cURL请求的经典交易部分(来自我收集的内容):

 "transactions":[
    {
      "amount":{
        "total":"7.47",
        "currency":"USD"
      }
    }
  ]

我想知道我需要的信息应该是什么样的,例如,如果我想传递userID,那么它是否会像

那样
"userID":"4",

它应该嵌套在其他参数中吗?

如果需要任何其他代码我会很乐意发布它,我确实广泛搜索了这个主题,我找到的所有答案都与表格和隐藏字段有关,对我而言并非如此。(如上所述,PayPal正在被激怒通过使用cURL的PHP​​函数。

提前致谢!

编辑:

您好!感谢您的回复,并感谢很多这个很棒的lib :) 我正在使用带有pay方法的Adaptive_payments控制器。

我刚刚意识到确实返回了invoiceID,这很合适。 我在你的答案中遗漏了一些东西,IPN没有返回很多字段,包括customerID(这是我尝试使用的,我只是假设没有返回)。

以下是IPN捕获的回报:

    cmd=_notify-validate
    &transaction_subject=
    &payment_date=12%3A02%3A40+Jan+29%2C+2014+PST
    &txn_type=web_accept
    &last_name=patrick
    &residence_country=US
    &item_name=
    &payment_gross=50.00
    &mc_currency=USD
    &business=test@example.com //not the actual email
    &payment_type=instant
    &protection_eligibility=Ineligible
    &verify_sign=ASsSVovq77sBsVg2xPiCnEG3N9AIAD1pW3tgoSX59hTmz9AA9lT6AH0E
    &payer_status=verified
    &test_ipn=1
    &tax=0.00
    &payer_email=patrick.buyer%40gmail.com
    &txn_id=69J264685H5924531&quantity=0
    &receiver_email=test@example.com //not the actual email
    &first_name=patrick
    &payer_id=5MLPF23854T8Q
    &receiver_id=F5K3CSR99E9WA
    &item_number=
    &payment_status=Completed
    &payment_fee=1.75
    &mc_fee=1.75
    &mc_gross=50.00
    &custom=
    &charset=windows-1252
    &notify_version=3.7
    &ipn_track_id=50879f4bb9d2

似乎并非所有控制器的控件都由IPN返回。 发票将非常适合我,我会标记为已回答。 非常感谢您的时间和精力。

编辑2: $ PayPalResult ['RawResponse']由于某种原因不存在,我做了一个$ PayPalResult的var_dump(在adaptive_dayment控制器中,就在我重定向到paypal之前)。

array(10) {
  ["Errors"]=>
  array(0) {
  }
  ["Ack"]=>
  string(7) "Success"
  ["Build"]=>
  string(7) "7935900"
  ["CorrelationID"]=>
  string(13) "8c2afcee2d74b"
  ["Timestamp"]=>
  string(29) "2014-01-31T02:37:38.806-08:00"
  ["PayKey"]=>
  string(20) "AP-1WW538504G900525L"
  ["PaymentExecStatus"]=>
  string(7) "CREATED"
  ["RedirectURL"]=>
  string(81) "https://www.sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=AP-1WW538504G900525L"
  ["XMLRequest"]=>
  string(1439) "ReturnAllen_USPAYhttp://httpexample.no-ip.biz/ROOT/index.php/userControllers/regularuserActions/viewShoppingCartAPP-80W284485P519543T109.67.55.127USDBALANCECREDITCARDhttp://httpexample.no-ip.biz/root/index.php/main/IPNIPN100XXXXXXX@gmail.com5SERVICEfalsehttp://httpexample.no-ip.biz/ROOT/index.php/userControllers/regularuserActions/paypalSuccess"
  ["XMLResponse"]=>
  string(373) "2014-01-31T02:37:38.806-08:00Success8c2afcee2d74b7935900AP-1WW538504G900525LCREATED"
}

简而言之,我的IPN类正在被调用,但它无法找到任何要处理的信息(我已经用日志确认了这一点,调试显示该类被调用但没有$ _POST数据存在)。

编辑3:

生成XML请求很好,我测试的特定属性是myownID - 它出现在请求中。

由于某种原因,虽然没有发回$ _POST信息。 IPN方法中的这一行:

$ this-> _log('debug - 应用程序的IPN导出为'。var_export($ _POST));

在我的日志中显示如下:  debug - 应用程序的IPN导出

[XMLRequest] =&gt; <?xml version="1.0" encoding="utf-8"?><PayRequest xmlns="http://svcs.paypal.com/types/ap"><requestEnvelope xmlns=""><detailLevel>ReturnAll</detailLevel><errorLanguage>en_US</errorLanguage></requestEnvelope><actionType xmlns="">PAY</actionType><cancelUrl xmlns="">http://httpexample.no-ip.biz/ROOT/index.php/userControllers/regularuserActions/viewShoppingCart</cancelUrl><clientDetails xmlns=""><applicationId xmlns="">APP-80W284485P519543T</applicationId><customerId xmlns="">myownID</customerId><geoLocation xmlns="">Israel</geoLocation><ipAddress xmlns="">109.67.55.127</ipAddress></clientDetails><currencyCode xmlns="">ILS</currencyCode><fundingConstraint xmlns=""><allowedFundingType xmlns=""><fundingTypeInfo xmlns=""><fundingType xmlns="">BALANCE</fundingType></fundingTypeInfo><fundingTypeInfo xmlns=""><fundingType xmlns="">CREDITCARD</fundingType></fundingTypeInfo></allowedFundingType></fundingConstraint><ipnNotificationUrl xmlns="">http://httpexample.no-ip.biz/root/index.php/main/IPN</ipnNotificationUrl><receiverList xmlns=""><receiver xmlns=""><amount xmlns="">25</amount><email xmlns="">XXXXXX@gmail.com</email><invoiceId xmlns="">5</invoiceId><paymentType xmlns="">SERVICE</paymentType><primary xmlns="">false</primary></receiver></receiverList><sender><useCredentials xmlns=""></useCredentials></sender><account xmlns=""><phone xmlns=""></phone></account><returnUrl xmlns="">http://httpexample.no-ip.biz/ROOT/index.php/userControllers/regularuserActions/paypalSuccess</returnUrl></PayRequest>

编辑:从应用程序IPN收到我的IPN方法的最新IPN属性。

cmd=_notify-validate&
transaction=
&payment_request_date=Sun+Feb+02+08%3A25%3A52+PST+2014
&return_url=http%3A%2F%2Fhttpexample.no-ip.biz%2FROOT%2Findex.php%2FuserControllers%2FregularuserActions%2FpaypalSuccess
&fees_payer=EACHRECEIVER
&ipn_notification_url=http%3A%2F%2Fhttpexample.no-ip.biz%2Froot%2Findex.php%2Fpaypal%2Fpaypal_ipn%2Frunagain
&sender_email=patrick.buyer%40gmail.com
&verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31AwGY-gIhQZM2WI9Ae63J.CxI7j4y
&test_ipn=1
&cancel_url=http%3A%2F%2Fhttpexample.no-ip.biz%2FROOT%2Findex.php%2FuserControllers%2FregularuserActions%2FviewShoppingCart
&pay_key=AP-6RR41041VH869594S
&action_type=PAY
&transaction_type=Adaptive+Payment+PAY
&status=COMPLETED
&log_default_shipping_address_in_transaction=false
&charset=windows-1252
&notify_version=UNVERSIONED
&reverse_all_parallel_payments_on_error=false

1 个答案:

答案 0 :(得分:0)

我是该图书馆的开发者,我很乐意提供帮助。您发布的JSON内容是指PayPal的新REST API,但这不是我的库所使用的。它使用classic API's,它比今天的REST API更加成熟,限制更少。

您正在使用哪种API?该库带有已设置的控制器,并包含请求中可能的所有参数。请求中包含的任何数据也会以IPN形式返回。

如果您需要包含自定义字段,则需要在可用时使用CUSTOM参数,或者另一个选项是在数据库中保存数据,然后在CUSTOM或INVNUM中传递记录ID。这样,ID就会以IPN的形式返回,您可以将所有详细信息从数据库中撤回。

如果您正在使用Pay API,则可以在$ Receiver数据中包含InvoiceID参数,该参数已包含在Pay()的控制器方法中。 Pay_with_options()结合了Pay和SetPaymentOptions API,它提供了更多参数,包括可以使用的CustomID,也会返回IPN。

如果您提供有关您正在使用的确切API的详细信息,我可以为您提供更多帮助。