#ddgconsultant

1 messages · Page 1 of 1 (latest)

burnt flareBOT
opaque parrot
#

Hi what's your question?

teal quest
#

So .. I have a webservice -- There are two plans -- Users can either be a "one time" "life" plan --- or a "recurring" "gold" plan.

They only need to put their credit card information in at checkout (registration process)

I receive: Error: Cannot charge a customer that has no active card

#

when performing this PHP:

when performing this PHP:

// Validate form data
if (isset( $_POST['interval'])) $interval = $_POST['interval'];
if (isset( $_POST['plan'])) $plan = $_POST['plan'];
$amount = filter_input(INPUT_POST, 'amount', FILTER_VALIDATE_FLOAT);
$currency = filter_input(INPUT_POST, 'currency', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '/^(usd|eur|gbp)$/i']]);

if($amount === false || $currency === false) {
// Invalid data, return error
exit('Invalid amount or currency');
}

$paymentMethodId = filter_input(INPUT_POST, 'paymentMethod');

if(empty($paymentMethodId)) {
exit('No payment method provided');
}

opaque parrot
#

How do you collect payment method details? Payment Element?

teal quest
#

using: <script>
// Set your Stripe public key
const stripe = Stripe('<?PHP echo $STRIPE_API_Publishable_key; ?>');

// Create card element
const elements = stripe.elements();
const card = elements.create('card', {
style: {
base: {
iconColor: 'navy',
color: '#000',
fontWeight: '500',
fontFamily: 'Roboto, Open Sans, Segoe UI, sans-serif',
fontSize: '22px',
fontSmoothing: 'antialiased',
':-webkit-autofill': {
color: '#fce883',
},
'::placeholder': {
color: 'gold',
},
},
invalid: {
iconColor: '#FFC7EE',
color: 'red',
},
},
});

card.mount('#card-element');

const form = document.getElementById('payment-form');

form.addEventListener('submit', async event => {

event.preventDefault();

// Get payment method from card element
const {error, paymentMethod} = await stripe.createPaymentMethod({
type: 'card',
card: card
});

if (error) {
// Show error to customer
showError(error);
} else {
// Add payment method to form
const input = document.createElement('input');
input.type = 'hidden';
input.name = 'paymentMethod';
input.value = paymentMethod.id;
form.appendChild(input);

// Submit form
form.submit();

}

});

with my HTML form

#

I keep reading something about Payment Intents .. but I'm not comprehending

opaque parrot
#

Yeah your flow really isn't the recommended flow. Generally we don't recommend explicit payment method creation. Recommended flow is to create the Payment Intent up front, initialize the Payment Element with its client secret, then confirm the payment intent with the details provided in the Payment Element. See this guide for the recommended way to accept a payment: https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=elements

teal quest
#

as someone who just doesn't get it... is a "Payment Intent" card the customer is "going" to use???

opaque parrot
teal quest
#

but do I need that "if" the user picks the one time payment plan?

#

or is it just best to do the integration the same way for both plans?

opaque parrot
#

What do you mean?

#

Need what?

teal quest
#

I mean do I need to do the Payment Intent -> Payment Method -> Create Customer -> Charge Customer if all I'm doing is accepting a one time payment (I'm guessing on the order based on what I've read)

#

wouldn't it just be a "Charge" -- no customer creation required.

opaque parrot
#

You don't need to create a customer with payment intents either

#

Charges are the old flow

#

PaymentIntents are the newer version

teal quest
#

ah -- now that's helping me...

opaque parrot
#

Recommend reading the guides I sent first

teal quest
#

ok... that might have been where I got mixed up... perhaps me combining the two

#

thank you.

opaque parrot
#

No problem

teal quest
#

do you know when Stripe "switched" from Charges to PaymentIntents?

opaque parrot
#

Not sure exactly. Years ago

#

But Payment Intents are built on top of Charges