#jovan_paymentelement-country

1 messages ยท Page 1 of 1 (latest)

static lintelBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1226991794923901029

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

ember nymphBOT
short sail
#

@ocean thistle The country is saved on the PaymentMethod the same way after you call confirmPayment()

#

jovan_paymentelement-country

ocean thistle
#

Which object or method should I use here? to get the value of the country input?

short sail
#

Sorry I don't really get the ask, this is just a picture of a raw JS object.

#

Can you share your real code where you call confirmPayment() instead?

ocean thistle
#
function handleCardPayment(){
  const { error: submitError } = await elements.submit();
  if (submitError) {
    handleError(submitError);
    return;
  }

  const fields = {
    country: 'I WANT TO PUT COUNTRY VALUE HERE',
  }

  //Fetching Client Secret in Server
  const { clientSecret, status, message, link } = await fetchClientSecret(fields);

  if (status == 'error') {
    handleError({'message' : message});
    return;
  }
  // Confirm the PaymentIntent using the details collected by the Payment Element
  const setupIntent = await stripe.confirmSetup({
    elements,
    clientSecret,
    redirect: 'if_required'
  });

}

#

this one

#

As you can see, I want to put the country value on fields object.

short sail
#

yeah you can't you will only know the country after confirmSetup() completes

ocean thistle
#

Oh then why you can do this on payment request button:
const fullName = ev.paymentMethod.billing_details.name;

where there's a paymentMethod object

#

Are they different?

short sail
#

yes they are completely different integration paths.

#

In your flow you get a SetupIntent seti_123 back and that will have payment_method: 'pm_123' and then on your server you can retrieve that object and look at the billing_details on it. Not possible in JS client-side

ocean thistle
#

Okay, this is my current form. Is it really not possible to get the country value here?

short sail
#

It is, after confirmSetup(). Impossible before.

ocean thistle
#

Okay, I'll give it a try

#

Another question, I just wanted to confirm if I implemented it correctly. Is this code will automatically charge the card after 30 days trial ended?

      // Create a subscription with 30 days trial
      $subscription = $this->stripe->subscriptions->create([
        'customer' => $customer->id,
        'items' => [
            [
              'price' => $_ENV['STARTER_PLAN'],
              'quantity' => $fields['client_allowed_members']
            ]
        ],
        'trial_period_days' => 30,
        'payment_behavior' => 'default_incomplete',
        'payment_settings' => [
          'save_default_payment_method' => 'on_subscription',
          'payment_method_types' => ['card'],
        ],
        'expand' => ['pending_setup_intent'],
        // 'metadata' => $metadata
      ]);
#

I tried to simulate it but I think it's working well?

short sail
#

yep as long as you collect card details for that trial it will automatically charge as expected which you seem to have done!

static lintelBOT
ocean thistle
#

Thanks for the confirmation!

#

I'll try getting the value of country now after confirmSetup()

ocean thistle
#

Thanks I got it.

#

Is there any reason why country cannot be fetched before confirmSetup?

rugged raft
#

๐Ÿ‘‹ There's no change event that would return this information so you need to wait until a customer submits the country value

ocean thistle
#

Is it for security purposes?

rugged raft
#

No, not for security purposes