Stripe Updating a customer's card info - stripe-payments

I am trying to implement Stripe in php and I try to avoid using html forms , I instead call the Stripe Hosted Checkout page for the first subscription payment. However, if for later invoices, the payment failed due to an expired card for example , I want my customer to be able to update his card info (or I can create a new customer object in Stripe belonging to this same person) but the important part is that I want him to enter his NEW credit card info in a stripe hosted form that will validate his new card number , CVV...
Is there any way to do that?
Currently I am doing this :
document.getElementById("subscribe-now").addEventListener("click", function(evt) {
createCheckoutSession('<?php echo Config::SUBSCRIPTION_PLAN_ID; ?>').then(function(data) {
stripe.redirectToCheckout({
sessionId: data.id
}).then(handleResult);
});

Yes, that's supported by the Customer Portal. Similar to Checkout, this is a Stripe-hosted service that allows your customers to manage subscriptions and saved payment methods according to the configuration you provide, and you redirect your customers to it.
Preview here.

Related

Stripe APi paymentIntent and sessions object

I am having trouble finding out the difference between payment Intent and a session.
Assuming I a customer logs into a page and goes to domain.com/register how can I create session and check if customer has already visited page by using customer email address to get the customer object?
What are the difference between paymentIntent and session and how do they help? I see that session is created on Checkout but not when accepting one time payments.
Current I create a payment intent and it works find but my 'url' has no session
PaymentIntents
A PaymentIntent is an API object in Stripe's API that create encapsulates a lifecycle of a one-time payment.
You typically create your own form on your webpage when using PaymentIntents, create a PaymentIntent using the Stripe API, then confirm it using the cardElement from Stripe Elements (the frontend UI elements for collecting card details).
Checkout
Checkout is a full page "hosted UI" that creates its own PaymentIntent and provides all the UI that a customer needs to enter their card details and takes a payment. It also supports many other payment methods automatically without you having to manually add support for each one.
So a CheckoutSession under the hood uses a Subscription or a PaymentIntent object, depending on whether it was used in subscription or payment mode.

payment intent is null in a subscription checkout session

I am integrating stripe using php by following this tutorial:
https://phppot.com/php/manage-recurring-payments-using-stripe-billing-in-php/
(my website has some subscription plans and redirects to the stripe checkout form ) . however, for the last step, I decided not to use webhooks, I chose to store the info like in this tutorial https://www.codexworld.com/stripe-checkout-payment-gateway-integration-php/ (I know it is not for subscription but I just use the success.php code from this tutorial to collect the customer info and payment intent details).
I tested it, gone throught the stripe checkout form , and on success I printed the checkout session object and noticed that the payment_intent field of that object is empty ! so i cannot load the payment intent object and get its info although the payment is successfully made and it is showing on the dashboard . any idea why ??
EDIT :
According to the documenttaion of a checkout session (https://stripe.com/docs/api/checkout/sessions/object), the payment_intent field stores the ID of the PaymentIntent for Checkout Sessions in payment mode. In my case I have a subscription mode not a payment one. however,if I still want to get the $intent->status , can I use the payment_status field of the session object $checkout_session->payment_status?
And if subcription payments really don't have paymentintents , then why did the payment appear in the payments section on the dashboard?
Based on the mode you passed in, either one of payment_intent, subscription or setup_intent will be populated, the rest will be null.
When a Subscription is made, your user is invoiced so it is considered a payment and will appear in the Payments dashboard. You can retrieve the Subscription and access the latest_invoice field to obtain the Invoice object. The Invoice object contains the payment_intent field. This is likely what you're looking for.
Using webhook would simplify the process, since you could listen to invoice.payment_suceeded to retrieve the PaymentIntent ID.

Stripe later payment direct charges, create token error, The customer must have an active payment source attached

I am trying to make a Stripe later payment direct charge on a connected account in Node.js. This is all in test mode using the paymentMethods API.
I create a customer and attach a payment method with stripe.setupIntents.create() and am able to make later payments to my stripe account/the platform without any issues. However I would like to make a direct payment to a connected account using stripe.paymentIntents.create().
Following this guide, https://stripe.com/docs/connect/cloning-saved-payment-methods, I am under the impression I can clone a payment method used for my platform and use it to make a direct payment for a connected account. I attempt to create a token for the customer but receive the error "The customer must have an active payment source attached." despite the customer having an active default payment method that works for my platform, 'pm_1HFjvsLIOnOaY98HTxPugN5i'.
const token = await stripe.tokens.create({customer: 'cus_HpOf9y6TJ5XYlA'}, { stripeAccount: 'acct_1HDuHbBwYBNGN1ir'}
I am further confused by this guide https://stripe.com/docs/payments/payment-methods/connect#cloning-payment-methods, is this just an alternative method to accomplish essentially the same thing? Or do I need to create a new payment method onto the connected account, but wouldn't that defeat the purpose of creating a token?
Great question! In the API call you shared, you're passing only the customer parameter. Cloning a Payment Method requires passing both customer and payment_method like so:
const paymentMethod = await stripe.paymentMethods.create({
customer: 'cus_HpOf9y6TJ5XYlA',
payment_method: 'pm_1HFjvsLIOnOaY98HTxPugN5i',
}, {
stripeAccount: 'acct_1HDuHbBwYBNGN1ir',
});
With Payment Methods there's no concept of a "default source" for a customer—When creating a charge or sharing a payment method you must always specify both the customer ID and payment method ID. The exception to this is Subscriptions, which will look at the invoice_settings.default_payment_method property on the customer and use that for subscription and invoice payments.

Stripe: Is there an element that creates a customer without a charge?

Does Stripe have an element that would capture a customers card details but not process any payment?
In my case, I have a form that a client fills out but payment is not processed at that time as the final charges will always change based on what the client needs are. Payment would be processed at a later date.
I did see that WordPress / gravity forms have a module that does this but I would rather not have to create a WordPress site.
You can use Stripe.js with Elements (https://stripe.com/docs/stripe-js) or Stripe Checkout (https://stripe.com/docs/checkout) to collect your customer's card details securely.
Both Stripe.js and Checkout allow you to tokenize a user's credit card details. You can then use those that token/source on your backend to create a new Customer with that token [0] or update an existing Customer.
The Stripe recipe's page actually has an example of using Stripe Checkout to update a user's card details (https://stripe.com/docs/recipes/updating-customer-cards#using-the-token-to-update-the-customers-card).
[0] https://stripe.com/docs/api/customers/create?lang=node#create_customer-source
Hope that helps!
UPDATE: adding that the new version of Stripe Checkout is a hosted page that allows collecting card details for future use via its Setup Mode: https://stripe.com/docs/payments/checkout/setup#retrieve-setupintent

Is that possible to pay someone using their registered Email ID on STRIPE

i m building a online selling store like ebay and I want to pay sellers by using their registered STRIPE email ID (foobar#example.com) (like paypal do so) without connecting him/her in my stripe platform .
Remember I want pay seller using his stripe Email Id not stripe account Id which looks like acct_123dsfg****
if you know how to do that please let me Know :) Thanks
Using stripe gateway you can pay your seller's by following 2 methods only:
1) Seller can configure their stripe account from store dashboard (by adding their publishable key and secret key) and site admin transfer the appropriate amount into seller account.
2) Using stripe connect ( https://stripe.com/docs/connect ).
I think currently stripe do not provide any such functionality that you can pay your seller's using their stripe email id only.

Resources