#MaxFx2-Paymentelement

1 messages · Page 1 of 1 (latest)

peak dew
topaz maple
#

yes, but how can i get "source"?

#

i haw payment

peak dew
#

Your customer already has PaymentMethod, why do you need the source?

topaz maple
#

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

peak dew
#

Customer Id?

#

I think because that PaymentMethod is not default

topaz maple
#

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

lament portal
#

Hey! Taking over from @peak dew – let me catch up

#

What are you trying to accomplish?

topaz maple
#

Hey. I want to create a charge for customer.

lament portal
#

Your amount parameter is invalid - needs to be an integer

topaz maple
#

31284?

lament portal
#

If your intention is to charge $312.84 USD, then yes

topaz maple
#

not work

lament portal
#

You need to pass the source parameter as the Customer object doesn't have a default payment method

topaz maple
#

this is where this branch started, I asked how to do it?

topaz maple
lament portal
#

You should be using Payment Intents, not Charges

topaz maple
#

I have payment method, i need to create charge. If need create cart, how do it?

lament portal
#

Well, are you passing that Customer ID when creating the Charge?

topaz maple
#

cus_KhaNCjQf1at9C8

#

cus_KhaNCjQf1at9C8

lament portal
#

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)

topaz maple
#

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);
        }
    });
lament portal
#

But are you creating the Setup Intent before all this?

topaz maple
#

$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);
lament portal
#

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

topaz maple
#

$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);

lament portal
#

Yeah, so you need to be using Payment Intents and not Charges

topaz maple
lament portal
topaz maple
#

ok, I will try, thank you

lament portal
#

Np!