Reputation: 1936
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
Upvotes: 0
Views: 100
Reputation: 26056
With the Adaptive Payments platform you have to sort of think about things in 2 parts:
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.
Upvotes: 1