2

这是我的控制器:

setup_purchase方法对我的数据 api 确实适用,但preapprove_payment方法不起作用。

def pay
 gateway =  ActiveMerchant::Billing::PaypalAdaptivePayment.new(
  :login => "email",
  :password => "pass",
  :signature => "signature",
  :appid => "APP-80W284485P519543T" )
  response = gateway.preapprove_payment( 
  :return_url => user_orders_url(current_user),
  :cancel_url => user_orders_url(current_user),
  :sender_email =>"email",
  :start_date => Time.now,
  :end_date => Time.now,
  :currency_code =>"USD",
  :max_amount => "20",
  :maxNumberOfPayments => "2")
  puts response.preapproval_key
  puts gateway.debug
  # for redirecting the customer to the actual paypal site to finish the payment.
  redirect_to (gateway.redirect_url_for(response["preapproval_key"]))
end

我进入日志:

PA-8K9332086D720151L
{:url=>#<URI::HTTPS:0xdf9bd18 URL:https://svcs.sandbox.paypal.com/AdaptivePayments/Preapproval>, :request=>"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<PreapprovalRequest>\n  <requestEnvelope>\n    <detailLevel>ReturnAll</detailLevel>\n    <errorLanguage>en_US</errorLanguage>\n    <senderEmail>email</senderEmail>\n  </requestEnvelope>\n  <endingDate>2012-07-20T19:09:20</endingDate>\n  <startingDate>2012-07-20T19:09:20</startingDate>\n  <maxTotalAmountOfAllPayments>20</maxTotalAmountOfAllPayments>\n  <maxNumberOfPayments>2</maxNumberOfPayments>\n  <currencyCode>USD</currencyCode>\n  <cancelUrl>http://localhost:3000/en/u/maserranocaceres/orders</cancelUrl>\n  <returnUrl>http://localhost:3000/en/u/maserranocaceres/orders</returnUrl>\n</PreapprovalRequest>\n", :response=>"{\"responseEnvelope\":{\"timestamp\":\"2012-07-20T10:09:22.459-07:00\",\"ack\":\"Success\",\"correlationId\":\"ada6a3e7da93d\",\"build\":\"DEV\"},\"preapprovalKey\":\"PA-8K9332086D720151L\"}"}

完整回复:

#<ActiveMerchant::Billing::AdaptivePaymentResponse:0xc817278 @json="{\"responseEnvelope\":{\"timestamp\":\"2012-07-23T07:43:56.603-07:00\",\"ack\":\"Success\",\"correlationId\":\"7f759c5da73ad\",\"build\":\"DEV\"},\"preapprovalKey\":\"PA-1M101813XU7801314\"}", @response=#<Hashie::Rash preapproval_key="PA-1M101813XU7801314" response_envelope=#<Hashie::Rash ack="Success" build="DEV" correlation_id="7f759c5da73ad" timestamp="2012-07-23T07:43:56.603-07:00">>, @xml_request="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<PreapprovalRequest>\n  <requestEnvelope>\n    <detailLevel>ReturnAll</detailLevel>\n    <errorLanguage>en_US</errorLanguage>\n    <senderEmail>microf_1342709161_per@gmail.com</senderEmail>\n  </requestEnvelope>\n  <endingDate>2012-08-22T16:43:54</endingDate>\n  <startingDate>2012-07-23T16:43:54</startingDate>\n  <maxTotalAmountOfAllPayments>20</maxTotalAmountOfAllPayments>\n  <maxNumberOfPayments>1</maxNumberOfPayments>\n  <currencyCode>USD</currencyCode>\n  <cancelUrl>http://localhost:3000/en/u/maserranocaceres/orders</cancelUrl>\n  <returnUrl>http://localhost:3000/en/u/maserranocaceres/orders</returnUrl>\n</PreapprovalRequest>\n", @request={"PreapprovalRequest"=>{"requestEnvelope"=>{"detailLevel"=>"ReturnAll", "errorLanguage"=>"en_US", "senderEmail"=>"email"}, "endingDate"=>"2012-08-22T16:43:54", "startingDate"=>"2012-07-23T16:43:54", "maxTotalAmountOfAllPayments"=>"20", "maxNumberOfPayments"=>"1", "currencyCode"=>"USD", "cancelUrl"=>"http://localhost:3000/en/u/maserranocaceres/orders", "returnUrl"=>"http://localhost:3000/en/u/maserranocaceres/orders"}}, @action="Preapproval">

我究竟做错了什么?

4

1 回答 1

1

问题已解决。

改变

gateway.redirect_url_for(response["preapprovalKey"])

gateway.redirect_pre_approval_url_for(response["preapprovalKey"])

正确的方法是redirect_pre_approval_url_for

你可以在这篇文章中看到修复:

在 Rails 3.2 中使用贝宝预先批准的付款

非常感谢!

于 2012-08-04T10:54:19.500 回答