Stripe collect payment later workflow Node/Express/EJS - javascript

I am working on the payment portion of an app using Stripe and having trouble trying to figure out the best way to route customers. Essentially, the way the app is supposed to work is:
Customer goes to site to enters payment details.
Payment is broken into two parts the Fee and the Deposit.
Customer submits payment details.
If the funds are validated they are brought to a success page.
If the funds are not validated they get an error page.
Later, the funds are captured either with or without the deposit amount.
I have Stripe set up where I am creating the payment intent with capture_method: 'manual' set so I can capture the funds later. I am passing the client secret to the front via EJS, and using stripe.confirmCardPayment() to 'run' the card. All of that seems to be working fine and they are correctly showing up in my Stripe dashboard as uncaptured payments. So, from here what is the best way to route the user to the correct page after the card is 'run'. In other words, if the funds are there then route to success pages, otherwise route to an error page. There needs to be some validation on the server side otherwise the customer could just directly visit the success page route without paying. Thanks for any help and ideas!

stripe.confirmCardPayment returns a Promise that resolves with result.error if there were errors (like the charge declined) or with result.paymentIntent if the PaymentIntent confirmation succeeds: https://stripe.com/docs/js/payment_intents/confirm_card_payment
Once your confirmCardPayment() Promise resolves, you can look at result.paymentIntent.status (which in your case would be requires_capture).
During this, you can make any arbitrary calls to your server (like pass the PaymentIntent/Customer ID and update your database) and then redirect your customer to the success/failure page accordingly.

Related

Paypal Smart Checkout – Multiple merchant ids throw error

On a checkout page, loading the PayPal Javascript SDK, I provide multiple merchant-ids like this (where [my_client_id] is replaced with my id, of course), the email addresses shown have been modified for privacy reasons:
<script src="https://www.paypal.com/sdk/js?client-id=[my_client_id]&currency=EUR&locale=de_DE&merchant-id=*"
data-merchant-id="lobo***#gmail.com,suic***#squar***.de,einkauf#***-games.de,paypal#***.events,***#kst***.at"></script>
I then create a separate Paypal Smart button for each of the merchants. But although I provide the multiple merchant-ids, I will get the following error as soon as a payment button is clicked:
Error: Payee(s) passed in transaction does not match expected merchant
id. Please ensure you are passing merchant-id=****55TUNG or
merchant-id=lobo***#gmail.com to the sdk url.
But that merchant-id is provided in the URL as you can see above. If I press another merchant's pay button, I get the same error message but with that merchant's id listed in the error message.
The payee passed by the PHP script using createOrder is the corresponding email address of the merchant 100 percent correctly.
Is this a bug in the PayPal SDK or am I listing the merchant-ids maybe in the wrong way in the SDK-URL (though it is the way PayPal has described it a discussion on github)?
IMPORTANT SIDE NOTE: If I totally omit providing the merchant-ids in the SDK-URL, I get Javascript warnings about the missing merchant-id, but the payment buttons work just fine (which makes me sure that the PHP backend script is working 100 percent correctly), the payments are being processed.
What interesting, too: If I omit the merchant-ids in the SDK-URL, PayPal will render four different payment options, if I include the merchant-ids in the URL, then only two are shown (and both of them will throw the error).
All of this is referring to production mode.
Only pass a single merchant-id, and have it correspond to the payee that you are going to use.
Alternatively, pass no merchant-id at all, for transaction types that don't require it.

Need PayPal PDT Sample Code in Client JavaScript

I'm new to PayPal and its PDT. I've searched through many posts but they require Node.js or PHP to implement it. I don't have both, but I just want a simple return from PayPal PDT, telling my download.html that the purchase was successful so that I can safely display the product key to my customers and allow them to download my digital product, otherwise I will do something like this in my JavaScript:
If (purchaseFailed) {
window.location.replace('/404.html');
}
The reason that I do that is to prevent direct access to my download.html and reveal the product key without making a payment through PayPal.
I've enabled my PayPal PDT and specified the return URL, but I just do not know how to write the JavaScript to get the return the status from PayPal. I do not need to display any transaction detail to my customers except a 'thank you' message, the product key, and the download link (but if you can show some sample on getting the transaction details, e.g. product code and customer email address, that would help too). Can somebody help me with some simple JavaScript that my Google Blogger HTML can execute it? Thanks a lot!
PDT is completely unreliable, because returns are never guaranteed to happen, due to browser/network crashes or the customer not waiting for the auto-return (there is a timer) or not clicking through to return (typically guests w/o an account must be shown a receipt and click to return). So PDT is suitable for informational purposes only (e.g. showing buyers a thank you message when they do return.).
Absolutely no business logic such as downloads should depend on a PDT return actually occurring.
Instead, if you need a dependable notification from PayPal of payment completion, an asynchronous IPN or one of the newer webhooks should be listened for -- or alternatively, the integration should be changed to a more robust synchronous server-side one such as this pattern: https://developer.paypal.com/demo/checkout/#/pattern/server , where there is always an immediate API response on payment capture for notification purposes.
Blogger's HTML/JS does not provide any of the necessary listening or API capabilities, of course.

How to know if Paypal transaction was successful using the API?

I try to integrate PayPal into my checkout process. Here is what I did:
I managed to use the Paypal API Node SDK to create payments with PayPal.payment.create.
and then redirecting the user to the payment URL I get in the response to links[1].href which is something like this: "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-00N000849T505604G".
On that page I sing in with my sandbox user and pay the transaction, I get redirected to my custom success page I declared when creating the payment.
On my Success Page, I want now to check if the transaction really was successful to update my database, so I call my backend, that calls a GET to the transaction to the links[0].href which is something like https://api.sandbox.paypal.com/v1/payments/payment/PAY-1VL72645VS000000XLLARPMI to check for the status.
Unfortunately, the state property of the response is always created.
What am I doing wrong? How can I check it? I was using these docs as a reference.
Generally, I’m a bit overwhelmed by the number of docs and not sure which one is correct and could not find any concise tutorial :S
Thanks for your help!
State property of the response is created is the current one.
The state property's possible values created, approved, failed.
created. The transaction was successfully created.
approved. The customer approved the transaction.
failed. The transaction request failed.
but approved. should be The buyer( not customer) approved the transaction.
You can get this from Payment.php file in line #376 of PayPal-PHP-SDK project.
https://github.com/paypal/PayPal-PHP-SDK/blob/master/lib/PayPal/Api/Payment.php
At first State property will created but it will be approved when The buyer approved the transaction using Update payment then you can check List payments /Show payment details then you will found payment is now approved.
For Update payment
https://developer.paypal.com/docs/api/payments/#payment_update
and Show payment details https://developer.paypal.com/docs/api/payments/#payment_get

Stripe Add CreditCard ID response is different from Dashboard

Currently using Stripe Test Mode I add a credit card using this. The card is added successfully to Stripe Dashboard. But when I was looking closer, the card id returned by the 'stripeResponseHandler' is different to what it is set on the Stripe Dashboard.
What was written to Stripe Dashboard:
Card ID: card_19FxJYDJ3JQRgrDjabcdELef
What the stripeResponseHandler actually returned:
Card ID: card_19FxJYDJ3JQRgrDjcOlENnWX
I used different testing credit card numbers and no errors are apparently returned, same behavior. What can cause this?
This is expected behavior. You shouldn't worry about the card ID you receive in the stripeResponseHandler callback in your frontend code. In the vast majority of cases, all you need to do in the callback is get the token ID ("tok_...") and send it to your backend code so it can be used in an API request, e.g. to create a charge or a customer.

Ember Simple Auth: how to keep data in a step by step process after redirection to login route

I'm creating an app using Ember.js. This application allows to book an appointment at the doctor.
You have a booking process with a few steps.
After step 1 (booking/start), you have a screen that shows up if the user isn't connected (booking/user). On this page, I have two links: one to the login page, another one to the registration page. All steps "needs" booking controller.
The link to login is basically a link to the next step (booking/confirmation), but since user isn't logged in, he's automatically redirected to login page by AuthenticatedRouteMixin. When I log in, everything works fine, I'm connected and redirected to booking/confirmation.
BUT, I lose all the data from my booking controller. It's obvious, since login doesn't have any connection with my booking controller.
I believe this is not a pure Ember Simple Auth question, but more a general Ember.js question. Do you have any idea about how I should change the login behavior to keep the data or change the logic of the app to save the data before going to the login page, then retrieve it on booking/confirmation?
My code is available here: https://github.com/lionelrudaz/wellnow-frontend
Let me know if you need more information.
I found a workaround. When I enter the process, I create and save a booking object, allowing me to have an id and to save the progress at every steps.
If you need more details, just let me know.

Categories

Resources