#ddgconsultant
1 messages · Page 1 of 1 (latest)
Hi what's your question?
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');
}
How do you collect payment method details? Payment Element?
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
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
You can use that same approach with a subscription as well (up-front creation + payment element). See https://stripe.com/docs/billing/subscriptions/build-subscriptions?ui=elements
as someone who just doesn't get it... is a "Payment Intent" card the customer is "going" to use???
No. A Payment Intent is an api object that represents a payment. See: https://stripe.com/docs/payments/payment-intents
This should also help: https://stripe.com/docs/payments/paymentintents/lifecycle
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?
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.
You don't need to create a customer with payment intents either
Charges are the old flow
PaymentIntents are the newer version
ah -- now that's helping me...
Recommend reading the guides I sent first
ok... that might have been where I got mixed up... perhaps me combining the two
thank you.
No problem
do you know when Stripe "switched" from Charges to PaymentIntents?