Paypal invalid token error when creating a recurring payment profile - ruby-on-rails

I am trying to setup a recurring payment profile via the ExpressCheckout API of Paypal in Ruby on Rails with the help of paypal-express gem but i keep getting error code 11502 (Invalid token) => Paypal error code documentation
The documentation is a bit unclear because there it is not saying what's missing:
One or more subscription detail fields are missing from the request.
I have checked the required field in the documentation here but i don't think i missed any. No need for shipping details as we don't ship a product.
Here is a log of what is being sent to Paypal when i am doing the checkout and then creating the recurring profile:
SetExpressCheckout
Parameters:
{:RETURNURL=>"http://localhost:3000/paypal/validate",
:CANCELURL=>"http://localhost:3000/paypal/cancel",
:REQCONFIRMSHIPPING=>0, :NOSHIPPING=>1, :ALLOWNOTE=>0,
:PAYMENTREQUEST_0_AMT=>"88.00", :PAYMENTREQUEST_0_TAXAMT=>"0.00",
:PAYMENTREQUEST_0_SHIPPINGAMT=>"0.00",
:PAYMENTREQUEST_0_CURRENCYCODE=>"HKD", :PAYMENTREQUEST_0_DESC=>"Plus x
2-month subscription x 2 staff", :LOCALECODE=>:fr}
Response:
TOKEN=EC%2d0H440138VJ9552235&TIMESTAMP=2015%2d04%2d25T08%3a38%3a42Z&CORRELATIONID>=48742557da98&ACK=Success&VERSION=88%2e0&BUILD=16428450
CreateRecurringPaymentsProfile
Parameters:
{:TOKEN=>"EC-0H440138VJ9552235", :BILLINGPERIOD=>:Month,
:BILLINGFREQUENCY=>2, :TOTALBILLINGCYCLES=>0, :AMT=>"88.00",
:CURRENCYCODE=>"HKD", :SHIPPINGAMT=>"0.00", :TAXAMT=>"0.00",
:DESC=>"Plus x 2-month subscription x 2 staff", :MAXFAILEDPAYMENTS=>0,
:PROFILESTARTDATE=>"2015-04-25 16:39:24"}
Response:
TIMESTAMP=2015%2d04%2d25T08%3a39%3a26Z&CORRELATIONID=533964ff183a1&ACK=Failure&VE>RSION=88%2e0&BUILD=16398710&L_ERRORCODE0=11502&L_SHORTMESSAGE0=Invalid%20Token&L_>LONGMESSAGE0=The
%20token%20is%20invalid&L_SEVERITYCODE0=Error
Do you guys have any ideas of what could be wrong? I can execute a payment without any issue, the issue appear when creating a recurring profile.

Never mind!
I found what was wrong misread the gem wiki (https://github.com/nov/paypal-express/wiki/Recurring-Payment) and mistakenly mix instant payment request with recurring profile creation so there was no billing_agreement_description nor billing_agreements in the data sent to paypal...

Related

How to handle payment success in stripe?

After a user visits the payments page and successfully makes a payment, Stripe will redirect the customer to whatever url is provided to success_url
Stripe.api_key = 'sk_test_51HYHSFGtUKse83O9J4QeAib3cp8sHzGaOQRrn7sba92Hd8dCHE3AIHe5ModevMK7TVAUCyJU0ADSwIUoX00qxZmBI9r'
session = Stripe::Checkout::Session.create({
payment_method_types: ['card'],
line_items: [{
name: 'Kavholm rental',
amount: 1000,
currency: 'aud',
quantity: 1,
}],
payment_intent_data: {
application_fee_amount: 123,
transfer_data: {
destination: '{{CONNECTED_STRIPE_ACCOUNT_ID}}',
},
},
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/failure',
})
Now the app/platform must arrange 'fulfillment':
After the payment is completed, you’ll need to handle any fulfillment necessary on your end. A home-rental company that requires payment upfront, for instance, would connect the homeowner with the renter after a successful payment.
Also (bold from me):
Do not rely on the redirect to the success_url param alone for fulfilling purchases as:
Malicious users could directly access the success_url without paying and gain access to your goods or services.
Customers may not always reach the success_url after a successful payment. It is possible they close their browser tab before the redirect occurs.
Up to this point, everything is very well explained in the stripe docs and very understandable.
But I want to know: what is the best thing to do next, noting that:
a payment may not go through immediately, so simply loading the success_url might be premature
a webhook can be (easily) configured to listen for events, however if the success_url is loaded even 1 second before the webhook receives a success message, then it won't know that the payment went through successfully (so, for example, displaying "Congrats, your product will be shipped!" message could be presumptuous
Question
So, finally, the question: what is best practice for the flow on from success_url? I am just confused as to what is the best pattern..
Ideas
Here are some things I've considered:
Upon routing to success_url, simply use sleep(5) and then check the webhook in the controller for the success_url so it takes 5 extra seconds to load giving the webhook a chance to receive incoming events, so you can display either "Congrats your product will be shipped!" or "Oh, no, something went wrong with your payment, please try again or contact your bank".
Routing directly to success_url, but then having a message saying "please refresh in a moment" (then listening for a webhook indicating the payment was successful, and then conditionally showing the "Congrats your product will be shipped!" message)
The documentation for fulfilling orders has this in an info box under the code snippet:
Your webhook endpoint redirects your customer to the success_url when you acknowledge you received the event. In scenarios where your endpoint is down or the event isn’t acknowledged properly, your handler redirects the customer to the success_url 10 seconds after a successful payment.
The event referenced above is the checkout.session.completed event sent to your webhook endpoint. The delay is designed to let you confirm the payment is successful and customize the success page based on the result of the Checkout Session's outcome.
In other words, Checkout won't send someone to your success_url until you've responded to the checkout.session.completed event request from your webhook endpoint with a successful (2xx) response, giving you time to customize the success page based on the outcome.
You can, for example, default to a "your payment is being processed" success page, but if you confirm the Checkout Session and payment succeeded after receiving the checkout.session.completed event, you can instead change the page to read "congrats your product will be shipped".
This approach means you can reliably present a success page that always has displays accurate information.

The merchant's account is not able to process transactions with activemerchant + Ruby on rails + Paypal

want to parse a payment with PayPal using active merchant I did all the setting but response get the error like this if anyone can help me out then its great thanks in advance :)
Response
======response===========#<ActiveMerchant::Billing::Response:0x00000000061820d0 #params={"timestamp"=>"2019-02-27T12:29:37Z", "ack"=>"Failure", "correlation_id"=>"21a7f98432854", "version"=>"124", "build"=>"46457558", "amount"=>"10.00", "amount_currency_id"=>"USD", "message"=>"This transaction cannot be processed. The merchant's account is not able to process transactions.", "error_codes"=>"10548", "Timestamp"=>"2019-02-27T12:29:37Z", "Ack"=>"Failure", "CorrelationID"=>"21a7f98432854", "Errors"=>{"ShortMessage"=>"Invalid Configuration", "LongMessage"=>"This transaction cannot be processed. The merchant's account is not able to process transactions.", "ErrorCode"=>"10548", "SeverityCode"=>"Error"}, "Version"=>"124", "Build"=>"46457558", "Amount"=>"10.00"}, #message="This transaction cannot be processed. The merchant's account is not able to process transactions.", #success=false, #test=true, #authorization=nil, #fraud_review=false, #error_code=:processing_error, #emv_authorization=nil, #avs_result={"code"=>nil, "message"=>nil, "street_match"=>nil, "postal_match"=>nil}, #cvv_result={"code"=>nil, "message"=>nil}>==========
**
Error: This transaction cannot be processed. The merchant's account is
not able to process transactions.
**
You would need to contact PayPal to get this error addressed. If you look here: https://support.picnet.net/hc/en-us/articles/114094053611-Understanding-PayPal-Website-Payments-Pro-error-messages under error ID 10548 it says the account is not setup as a business merchant account.

After payment success, amount is not reflecting in sand box (adaptive parallel payment)

I am using this gem 'paypal-sdk-adaptivepayments'in ruby on rails. I get success after payment but when i saw my accounts in sandbox no one user get payments and also the merchant account is not debited.
This is my response which I get from paypal after success
<PayPal::SDK::AdaptivePayments::DataTypes::PaymentDetailsResponse:0x00000007d3cfc8 #responseEnvelope=#<PayPal::SDK::AdaptivePayments::DataTypes::ResponseEnvelope:0x00000007d3cc80 #timestamp=Mon, 13 Jul 2015 00:04:03 -0700, #ack="Success", #correlationId="4a4043560f603", #build="17325060">, #cancelUrl="http://localhost:3000/payments/cancel", #currencyCode="USD", #ipnNotificationUrl="http://localhost:3000/payments/ipn_notify", #paymentInfoList=#<PayPal::SDK::AdaptivePayments::DataTypes::PaymentInfoList:0x00000007d33cc0 #paymentInfo=[#<PayPal::SDK::AdaptivePayments::DataTypes::PaymentInfo:0x00000007d33ba8 #receiver=#<PayPal::SDK::AdaptivePayments::DataTypes::Receiver:0x00000007d33ae0 #amount=160.0, #email="jaskaran#yopmail.com", #primary=false, #paymentType="SERVICE", #accountId="MNF7MDPJWJHJL">, #pendingRefund=false>, #<PayPal::SDK::AdaptivePayments::DataTypes::PaymentInfo:0x00000007d33388 #receiver=#<PayPal::SDK::AdaptivePayments::DataTypes::Receiver:0x00000007d33310 #amount=10.0, #email="user4paypal#yopmail.com", #primary=false, #paymentType="SERVICE", #accountId="HEPSP9YS5ZMPQ">, #pendingRefund=false>]>, #returnUrl="http://localhost:3000/payments/success", #status="CREATED", #payKey="AP-2G3459926X3244353", #actionType="PAY", #feesPayer="SENDER", #reverseAllParallelPaymentsOnError=false, #sender=#<PayPal::SDK::AdaptivePayments::DataTypes::SenderIdentifier:0x00000007d325f0 #useCredentials=false>>
Here is status is created, I want to change it completed, Is need to call any api to do this again?
Oh After searching 3 hours. I get the solution. :)
I had to add senderEmail parameter with the payer email. Thats it. In this way paypal let the transaction to be COMPLETED.

Balanced payments API test marketplace bank account verification

I am trying to verify a bank account on a TEST marketplace. I am using the Ruby client to work with the Balanced API.
I am creating a bank account with the test routing/account number. I then create a verification and finally confirm it using amount_1 = 1 and amount_2 = 1.
If I look in my marketplace logs everything looks great. All requests are 200, and I see the response from the confirmation as "succeeded" except the marketplace dashboard still shows the verification as pending.
If I try to debit the account it fails because
funding-source-not-debitable: Funding instrument cannot be debited
which I've been told is because it's not verified.
I'm not sure what else to try as the logs show it's working, but everything else acts as if it's not verified.
My Ruby code looks like this:
#account = Balanced::BankAccount.fetch("/bank_accounts/#{balanced_id}")
#for test marketplace auto verify
if !Rails.env.production?
verification = #account.verify
verification.confirm(
amount_1 = 1,
amount_2 = 1
)
end
That is the correct syntax, however, I believe you are later associating this bank account to a customer. Doing so resets the can_debit field to False. You should therefore associate your customer before creating a verification.

Paypal express checkout using activemerchant and ipn

I'm stuck with getting activemerchants paypal express ipn notification to work.
My workflow looks like this:
# authorize the payment user gets redirected..
def auth
...
gateway.setup_authorization(total_as_cents, setup_authorization_params)
...
end
# purchase the authorized sum
def purchase
...
purchase_params = {
token: #order.payment_params[:token],
payer_id: #order.payment_params[:payer_id],
currency: current_tenant.currency.unit,
notify_url: paypal_ipn_callback_url
}
response = gateway.purchase(total_as_cents, purchase_params)
...
end
In the paypal docs it says notify_url is deprecated they use PAYMENTREQUEST_n_NOTIFYURL instead. But I have no clue how to tell this my paypal express gateway.
My ipn callback doesn't get called so I assume the notifyurl param doesn't work anymore.
Paypal is in sandbox mode but that should make no difference right?
Any hints?
I believe that if you are using Paypal Express that means you are doing a deep integration with your system, and you don't need the IPN, you can get the response from
response = gateway.purchase(total_as_cents, purchase_params)
and get all information from it, and that response is an object
ActiveMerchant::Billing::PaypalExpressResponse
The IPN is used for the basic Paypal integration, with no API calls from your app, only Paypal URL redirect with params.

Resources