#MaxFx2-Paymentelement
1 messages · Page 1 of 1 (latest)
Hi, tok_mastercard is just a convenience alias for you to use at server side. On client side, you would want to use our Test card: https://stripe.com/docs/testing
Your customer already has PaymentMethod, why do you need the source?
to create charge
atal error: Uncaught (Status 402) (Request req_SqC4CPz7ilIZVl) Cannot charge a customer that has no active card thrown in /var/www/demo/2finn.madeinweb.pro/wp-content/themes/grissoft/payments/Stripe/lib/Exception/ApiErrorException.php on line 38
Array
(
[amount] => 312.84
[currency] => usd
[customer] => cus_KhaNCjQf1at9C8
[description] => aaaaaa
[metadata] => Array
(
[order_id] => 2
)
)
please tell me how can i make the default opalata method?
*paument methods
Hey! Taking over from @peak dew – let me catch up
What are you trying to accomplish?
Hey. I want to create a charge for customer.
Your amount parameter is invalid - needs to be an integer
31284?
If your intention is to charge $312.84 USD, then yes
not work
You need to pass the source parameter as the Customer object doesn't have a default payment method
this is where this branch started, I asked how to do it?
this
Seems like you're using the Payment Element? Are you following our payments guide? https://stripe.com/docs/payments/quickstart
You should be using Payment Intents, not Charges
I have payment method, i need to create charge. If need create cart, how do it?
Well, are you passing that Customer ID when creating the Charge?
As I said, you're mixing older APIs here (Charges) with newer APIs (Payment Methods)
My guess is that the payment method isn't set as the default_source on the Customer so it can't be charged like that (via Charges)
You should really follow this guide: https://stripe.com/docs/payments/quickstart
I have this form. the payment method to such a client is tied exactly through the form here
var block_selector = '#add_card_form';
var form = $(block_selector);
if(!form.length) return false;
var stipe_public = form.find('[name="stipe_public"]').val();
var client_secret = form.find('[name="client_secret"]').val();
var url = form.find('[name="url"]').val().split('&').join('&');
const stripe = Stripe(stipe_public);
const appearance = {
theme: 'stripe'
};
const options = {
clientSecret: client_secret,
appearance: appearance,
};
const elements = stripe.elements(options);
const paymentElement = elements.create('payment');
paymentElement.mount('#stripe_form');
form.on('submit', async function(e) {
e.preventDefault();
const {error} = await stripe.confirmSetup({
elements,
confirmParams: {
return_url: url,
}
});
if (error) {
form.find('.error').html(error.message);
}
});
But are you creating the Setup Intent before all this?
$client_secret = $payment->setupIntentsCreate($stripe_id);
?>
<script src="https://js.stripe.com/v3/"></script>
<div class="personal-area_right">
<div class="title-chat"><?php echo $payment_id ? 'Update' : 'Add'?> card</div>
<form id="add_card_form">
<input type="hidden" name="stipe_public" value="<?php the_field('stipe_public_key','option');?>">
<input type="hidden" name="client_secret" value="<?php echo $client_secret;?>">
<input type="hidden" name="url" value="<?php echo $success_url;?>">
<div id="stripe_form"></div>
<div class="error"></div>
<button class="button">send</button>
</form>
</div>
yes
var client_secret = form.find('[name="client_secret"]').val();
const options = {
clientSecret: client_secret,
appearance: appearance,
};
const elements = stripe.elements(options);
Ok, so you've successfully used a Setup Intent to save a payment method to a customer
But how are you now trying to make a charge for that customer
$payment_data = array(
'amount' => $data['amount'] * 100,
'currency' => 'usd',
'customer' => $customer->getPaymentData('stripe_id'),
'description' => 'aaaaaa',
'metadata' => array(
'order_id' => $data['order_id'],
),
);
//print_r($payment_data);exit;
$data = $payment->addCharge($payment_data);
Yeah, so you need to be using Payment Intents and not Charges
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
ok, I will try, thank you
Np!