#arielbo-php-subs

1 messages · Page 1 of 1 (latest)

open tapir
#

Hi there!

#

If you want to use Payment Element then you need the client secret to render it

#

So you would create the Sub and then pass the $subscription->latest_invoice->payment_intent->client_secret from your server to your client to render the element

worldly ravine
#

hi

#

just 'clientSecret' => $subscription->latest_invoice->payment_intent->client_secret,

#

thanks bismark, just this is neccesary to render or I need to callback something more?

open tapir
worldly ravine
#

good is really easy stripe element right?

open tapir
#

Depends mostly on what you are trying to do.

#

If you aren't an experienced developer you may want to consider using Stripe Checkout instead

worldly ravine
#

I understand

#

an additional question I have hidden the country of stripe element default desing, I would like to know if I can require the client to put their name and email in a mandatory way?

#

const paymentElement = elements.create("payment", {
fields: {
billingDetails: {
name: 'auto',
email: 'auto',
address: 'never',
}
}
});

open tapir
#

No, we will only collect it when it is required for the payment method. If you want to collect those fields all the time then you disable them in the Payment Element and build your own form to collect those and pass them to confirmPayment()

worldly ravine
#

I understand very clearly, could you give some example of how can I pass this by confirmPayment() please?

worldly ravine
#

And for what purpose do I do this in stripe elements, since I would have already created the subscription?

open tapir
#

That data relates to the PaymentMethod that you are collecting from your customer

#

Which you are using to pay the invoices for the Subscription

#

It is up to you if you want to collect email/name. It isn't required for all payment method types and Payment Element will collect it automatically if you set those fields to auto when it is required.

worldly ravine
#

when you say collect it automatically and when I put auto option in the fields, do you mean that stripe elements will automatically request the field when required?

open tapir
#

Yep

worldly ravine
#

and this is saved in the method of payment or in customer profile ?

open tapir
#

The billing details are associated with the paymentmethod

#

The paymentmethod is attached to the Customer

worldly ravine
#

bismark, thanks, please I have this error

#

Uncaught (in promise) IntegrationError: In order to create a payment element, you must pass a valid PaymentIntent or SetupIntent client secret when creating the Elements group.

e.g. stripe.elements({clientSecret: "{{CLIENT_SECRET}}"})
at Dn ((index):1:219051)
at Jn ((index):1:225807)
at new n ((index):1:229964)
at e.<anonymous> ((index):1:233199)
at e.create ((index):1:129746)
at initialize (stripe_checkout.js?v=0.1:58:43)

open tapir
#

What does your client side code look like?

worldly ravine
#

header('Content-Type: application/json');
try {
// retrieve JSON from POST body
$jsonStr = file_get_contents('php://input');
$json_obj = json_decode($jsonStr);

              $subscription = $stripe->subscriptions->create([
                'customer' => $json_obj->cus,
                'items' => [
                  ['price' => $json_obj->price_id],
                ],
                'cancel_at_period_end' => $json_obj->cancel_at_period_end, 
                'automatic_tax' => [
                  'enabled' => false,
                ],
                'coupon' => $cupon_id,
                'metadata' => ['d_item_description' => $json_obj->d_item_description, 'd_idv'=> $json_obj->d_idv, 'dteca_userid' => $json_obj->d_user_id, 'dteca_tipo' => $json_obj->item_tipo, 'dteca_clase' => $json_obj->item_clase, 'dteca_dispositivos'=>$json_obj->d_disp, 'dteca_code' => $json_obj->d_code, 'dteca_type_pi' => $json_obj->s_type_pi,'dteca_price_id' => $json_obj->price_id],
                'payment_behavior' => 'default_incomplete',
                'expand' => ['latest_invoice.payment_intent.'],
                ]);
                $output = [
                  'clientSecret' => $subscription->latest_invoice->payment_intent->client_secret,
                ];  

          } catch (Error $e) {
              http_response_code(500);
              echo json_encode(['error' => $e->getMessage()]);
          }
open tapir
#

Okay and your JS code?

worldly ravine
#

let elements;

  initialize();
  checkStatus();

  document
      .querySelector("#payment-form")
      .addEventListener("submit", handleSubmit);

  // Fetches a payment intent and captures the client secret
  async function initialize() {
      const { clientSecret } = await fetch("https://www.derechoteca.com/wp-content/themes/derechoteca/cpanel/stripe_create.php", {
          method: "POST",
          headers: { "Content-Type": "application/json" },
          body: JSON.stringify({
              item_tipo: item_tipo,
              item_clase: item_clase,
              cancel_at_period_end: cancel_at_period_end,
              price_id: s_precio_id,
              price: s_precio,
              s_product: s_product,
              cus: cus,
              d_service: d_service,
              d_idv: d_idv,
              d_disp: d_disp,
              s_type_pi: s_type_pi,
              d_user_id: d_user_id,
              d_code: d_code,
              s_couponid: s_couponid,
              d_item_description: d_item_description,
          }),
      }).then((r) => r.json());

      elements = stripe.elements({ clientSecret });
      console.log(clientSecret);
      const paymentElement = elements.create("payment", {
          fields: {
              billingDetails: {
                  name: 'auto',
                  email: 'auto',
                  address: 'never',
              }
          }
      });
      paymentElement.mount("#payment-element");
  }
open tapir
#

And are you seeing you clientsecret in that log?

worldly ravine
#

no

open tapir
#

K so you likely aren't hitting your server

#

Can you add an error log on your server for $jsonStr

#

To see if you are hitting your server at all

worldly ravine
#

Uncaught (in promise) IntegrationError: In order to create a payment element, you must pass a valid PaymentIntent or SetupIntent client secret when creating the Elements group.

e.g. stripe.elements({clientSecret: "{{CLIENT_SECRET}}"})
at Dn ((index):1:219051)
at Jn ((index):1:225807)
at new n ((index):1:229964)
at e.<anonymous> ((index):1:233199)
at e.create ((index):1:129746)
at initialize (stripe_checkout.js?v=0.1:58:43)

#

of course $jsonStr

#

how can I create one error log in my server for $jsonStr

#

?

#

sorry

open tapir
#

error_log($jsonStr)

worldly ravine
#

really good bismark

#

{"item_tipo":"Service","item_clase":"Subscription","cancel_at_period_end":"false","price_id":"price_1K4eX9HHulAmiNnD19gAwhLp","price":"1918","s_product":"prod_Kjh4QWNTHM7Byu","cus":"cus_LMrrccDzLWJirx","d_service":"d-jurisprudencia-bolivia-anual","d_idv":"21","d_disp":"3","s_type_pi":"simple","d_user_id":"507713","d_code":"TEST21","s_couponid":"80","d_item_description":"Acceso por 12 meses"}, referer: https://www.derechoteca.com/oferta/37/507713/50537bb472752e4bd99db91e37576dda

#

possible is cus

open tapir
#

Yeah you likely want to add an error_log to ensure your sub is actually getting created

worldly ravine
#

really good error_log for develop debug, let me create one cus in mode test maybe is this issue

worldly ravine
#

nothing work still

#

please which is the minimun data for create one subscription ?

vast glade
#

bismark had to head out, but i'm hopping in - are you seeing the requests to create a subscription in your dashboard request logs?

worldly ravine
#

yes

#

but not create

#

and I don-t see any error log

#

in stripe developer

#

I have this code to create subscription

#

// Create una suscripcion
$subscription = $stripe->subscriptions->create([
'customer' => $json_obj->cus,
'items' => [
['price' => $json_obj->price_id],
],
'cancel_at_period_end' => $json_obj->cancel_at_period_end,
'automatic_tax' => [
'enabled' => true,
],
'coupon' => $cupon_id,
'metadata' => ['d_item_description' => $json_obj->d_item_description, 'd_idv'=> $json_obj->d_idv, 'dteca_userid' => $json_obj->d_user_id, 'dteca_tipo' => $json_obj->item_tipo, 'dteca_clase' => $json_obj->item_clase, 'dteca_dispositivos'=>$json_obj->d_disp, 'dteca_code' => $json_obj->d_code, 'dteca_type_pi' => $json_obj->s_type_pi,'dteca_price_id' => $json_obj->price_id],
'payment_behavior' => 'default_incomplete',
'expand' => ['latest_invoice.payment_intent.'],
]);

#

but maybe you can help with some mininum to test please

vast glade
#

Well have you done some basic debugging of your code to verify that the requests are reaching your server (specifically the part that is creating the subscription)?

worldly ravine
#

yes I work in this, please

#

what seems strange to me is that I do not receive any errors in stripe dashborad logs

vast glade
#

Well have you added a log line right before your subscription creation and confirmed your hitting that part of your server? Have you logged out the subscription ID right after creation?

worldly ravine
#

$stripe->subscriptions->create which is the minimal data to create this subscription please?

#

yes my server works good without subscription see pi_3L3qhgHHulAmiNnD0CWyLAPm

vast glade
#

Really it's more important to make sure you're even hitting that part of your code before worrying about what the minimum set of parameters needed to create a subscription

worldly ravine
#

but when I try to create subscription not work

vast glade
#

If you're not seeing the Subscription requests in the dashboard, that means you're not making the subscription creation requests at all (if you were missing parameters you'd still see the failing requests)

worldly ravine
#

I think that is this

#

when I try with onetimepayment I use $paymentIntent = \Stripe\PaymentIntent::create([

#

but when I try create subscription I use this another format $stripe->subscriptions->create([

#

which is the equivalent ? sorry

vast glade
#

Sorry backing up for a minute here - did you do what I asked earlier to confirm that you are hitting your endpoint and have you added logs that you're getting to subscription creation?

#

Again, it's really important to confirm that you have everything routed up correctly - it's possible the differing format is the issue, but that should come up as an error much earlier (you're server wouldn't be able to run that code)

worldly ravine
#

now work thanks

#

is how can I call the secret pass

#

$stripe = new \Stripe\StripeClient(
'sk_test_51J5ddddddddd'
);

#

or \Stripe\Stripe::setApiKey('sk_test_51J5Ga .....

#

which is the difference between this two methods ?

vast glade
worldly ravine
#

now I have error logs The customer cus_LlN9pFliMhPNJd's location isn't recognized by the tax engine. Set an address on the customer object and verify with the tax[automatic_tax] status.

#

my customer have only email, in address you just need only country ? or more data ?

vast glade
#

That's specifically for Stripe Tax - is that something you need for your integration?

worldly ravine
#

yes I implement really good all

vast glade
full pilot
#

Hi @worldly ravine I'm taking over this thread

worldly ravine
#

hello Jack

#

please some ask

#

how can I hide this messague in stripe element: By providing us with your card details, you allow xxx to charge future payments to your card in accordance with the stipulated conditions.

full pilot
#

Did you pass the setup_future_usage param when creating the PaymentIntent?

worldly ravine
#

I just pass this:

#

$subscription = $stripe->subscriptions->create([
'customer' => $json_obj->cus,
'items' => [
['price' => $json_obj->price_id],
],
'cancel_at_period_end' => $json_obj->cancel_at_period_end,
'automatic_tax' => [
'enabled' => true,
],
'coupon' => $cupon_id,
'metadata' => ['d_item_description' => $json_obj->d_item_description],
'payment_behavior' => 'default_incomplete',
'expand' => ['latest_invoice.payment_intent.'],
]);

full pilot
#

I see, the PaymentMethod that you are collecting is for subscription, which involve recurring payments.

#

So that's why the message is shown to tell the customer that the card details are going to be reused for future payments.

#

You can't turn off this message when collecting a reusable payment method.

worldly ravine
#

thank you for your explanation, them i can-t do

#

in my js I see this messagues in english

#

const { paymentIntent } = await stripe.retrievePaymentIntent(clientSecret);

      switch (paymentIntent.status) {
          case "succeeded":
              showMessage("Payment succeeded!");
              break;
          case "processing":
              showMessage("Your payment is processing.");
              break;
          case "requires_payment_method":
              showMessage("Your payment was not successful, please try again.");
              break;
          default:
              showMessage("Something went wrong.");
              break;
      }
#

can I translte to another ? o exist some restriction ?

full pilot
#

Just want to understand the question, you want to display localized message to your customer based on the paymentIntent status?

worldly ravine
#

I really want to change these messages to Spanish, is there a problem with it for stripe element or should they be in English?

full pilot
#

Of course you can display the message in the language that is most suitable to your customer.

worldly ravine
#

thank you

#

how can I change your desing of stripe element ?

#

for something more minimal

full pilot
worldly ravine
#

thank you !

#

how can I test one pay with google pay ? is possible?

full pilot
#

Yes, you can test the payment in test mode, no charges will be made to your card.

#

However, you need to add an actual card to your Google Pay account first.

worldly ravine
#

I try, thanks , another ask , plase and how can I add more methods to stripe element ?

full pilot
#

But first you need to turn on these payment method in your Dashboard first.

worldly ravine
#

in which place can I turn please

full pilot
worldly ravine
#

I see this message We've detected that you are using payment_method_types to configure payment methods. To manage payment methods from this page, replace payment_method_types with automatic_payment_methods.
If you prefer to use payment_method_types, refer to the manual settings page.

full pilot
#

You can use either payment_method_types or automatic_payment_methods when using PaymentIntent and SetupIntent API.

#

This message just tell you there's another option (automatic) to present the available payment methods to your customers.

worldly ravine
#

but maybe you can show me in which place of file can I need to do this change? I can t found where

full pilot
#

Are you using PaymentIntent or SetupIntent anywhere in your application?

worldly ravine
#

Im sorry how can I see this ... which is the difference

full pilot
#

Just search PaymentIntent and SetupIntent in your source code.

worldly ravine
#

I m using subscription with stripe element

#

'clientSecret' => $subscription->latest_invoice->payment_intent->client_secret,

#

I mean payment_intent rigth ?

full pilot
worldly ravine
#

let see i you are understand me, please jack

full pilot
worldly ravine
#
  1. Enabled the payment methods in your Dashboard. All enabled Jack
#
  1. Added the payment methods for invoice? Yes are added but in my link just I see Card and Google Pay
#

maybe I need to do something in my code ? to show all methods?

#

to show all payment methods ?

full pilot
#

Can you share with me your merchant ID? you can find it from the Stripe Dashboard -> Settings ->Account Details

worldly ravine
#

of cours

#

acct_1J5GaKHHulAmiNnD

#

this ?

full pilot
#

Yes, give me a sec, let me take a look

worldly ravine
#

thanks

full pilot
#

The ACH Direct Debit is not enabled.

#

This is another payment method available in US for subscription.

worldly ravine
#

and what about another methods?

#

alipay and apple pay for example

full pilot
#

They either don't support subscription or not available in US.

#

Alipay is invite only, and Apple Pay supports subscription (except Mexico)

worldly ravine
#

ok how can I enable ACH Direct Debit ?

full pilot
worldly ravine
#

I add but now show in my landingpage

#

i need to add some code in stripe element ? maybe ?

full pilot
#

Can you create a new subscription and see if the new payment method is available in payment element?

worldly ravine
#

i need to add some code in stripe element ? maybe ?

#

to show apply and ach

full pilot
#

ACH is for customers in US, but your customer's billing address is a non-US address.

worldly ravine
#

ok, thank you , please I need to stripe element require name on card this is possbile ?

full pilot
#

The name is not a mandatory field for card payment, you can build your own field to collect your customer's name.

worldly ravine
#

and can I mandatory field ? in stripe element

#

i mean, make this name field must be required ?

full pilot
#

I'm afraid that there's no option to make name field mandatory in PaymentElement.

worldly ravine
#

how can I add with the same css style my own field sorry ?

full pilot