简体   繁体   中英

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.

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)

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
  2. Transaction(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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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