Need Quick Working Example of Stripe SetupIntent Process for PHP

Job ID: 36998721

Budget: $10 – $30 USD

Hi there. I need a quick working example of using SetupIntent to save a credit card for an existing Stripe Customer ID. See this example: https://stripe.com/docs/payments/accept-a-payment-deferred?type=payment

I use the Stripe PHP SDK, so if it was done in that style that would be great. For example:

// Create new customer
$customer = \Stripe\Customer::create([
'source' => $_POST['token'],
'email' => $user['email'],
'description' => $user['name'],
// 'customer' => 'cus_xxx',
]);

$paymentMethod = \Stripe\PaymentMethod::create([
'type' => 'card',
'card' => [
'number' => $_POST['token'],
'exp_month' => $_POST['exp_month'], // Replace with your form's exp_month
'exp_year' => $_POST['exp_year'], // Replace with your form's exp_year
'cvc' => $_POST['cvc'], // Replace with your form's cvc
],
]);

The part I really have trouble with is posting the token in a way where I can easily retrieve it and use it for saving the card or setting up a paymentintent with the card, etc.

Also, I'm not sure if the credit card object is part of the token object or not. It seems like some examples I see pass the credit card as a single object from the same process that creates the token and other examples I see maybe break out the credit card and the token id from the same token object.

I had an old dev who posted the token via Ajax to PHP for me for one feature and that was great, so it would be helpful to have a couple of examples of how I can pass and handle the token and the credit card variables.

I've attached some example files from my code and here's a link to the js files I'm using:
https://drive.google.com/drive/folders/1zI-J-Fdq5PRP5QkIeYY_lwdnD80RQvPK?usp=sharing

I can pay $50 for this.

Thanks!
Related categories: PHP AJAX MySQL HTML Stripe