简体   繁体   English

Paypal在Rails上的自适应支付会带来错误的成功

[英]Paypal Adaptive payments on Rails giving false Success

I am using the official Paypal Ruby adaptive payments gem in conjunction with the embedded payment flow to collect one time payments on my site. 我正在使用官方的Paypal Ruby自适应支付宝嵌入式支付流程来在我的网站上收集一次付款。

The payment itself is working correctly, however in my callback I wish to check if the payment went through. 付款本身运行正常,但是在我的回叫中,我希望检查付款是否成功。 When I query the payment using the code suggested here , success is true even if I cancel the payment. 当我使用此处建议的代码查询付款时,即使取消付款也成功。

require 'paypal-sdk-adaptivepayments'
@api = PayPal::SDK::AdaptivePayments::API.new

# Build request object
@payment_details = @api.build_payment_details({
  :payKey => "AP-xxxxxxxxxxxxxxxx" })

# Make API call & get response
@payment_details_response = @api.payment_details(@payment_details)

# Access Response
if @payment_details_response.success?
  # Comes in here every time as @payment_details_response.success? always = true
else 
  @payment_details_response.error
end

How do I go about checking if the payment was cancelled? 如何检查付款是否已取消? (By cancelled the payment I mean click the X on the popup) (取消付款是指在弹出窗口中点击X)

Update: I've found a workaround for now, but its strange how the success? 更新:我现在已经找到一种解决方法,但是奇怪的是如何成功? is always true 永远是真的

if @payment_details_response.paymentInfoList.paymentInfo[0].transactionStatus 
    && @payment_details_response.paymentInfoList.paymentInfo[0].transactionStatus == "COMPLETED"
    #success
else
    #fail
end 

With the Adaptive Payments platform you have to sort of think about things in 2 parts: 使用自适应支付平台,您必须分两部分来考虑:

  1. API Call API调用
  2. Transaction(s) 交易(S)

The API call could very well be successful while the transaction(s) is not completed, and that seems to be what you're running into here, so what you've done would be correct in my opinion. 当事务未完成时,API调用很可能会成功,这似乎就是您在此处遇到的问题,因此我认为您所做的是正确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM