#arielbo-php-subs
1 messages · Page 1 of 1 (latest)
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
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?
Just the client_secret. Have you read through https://stripe.com/docs/billing/subscriptions/build-subscriptions?ui=elements?
good is really easy stripe element right?
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
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',
}
}
});
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()
I understand very clearly, could you give some example of how can I pass this by confirmPayment() please?
And for what purpose do I do this in stripe elements, since I would have already created the subscription?
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.
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?
Yep
and this is saved in the method of payment or in customer profile ?
The billing details are associated with the paymentmethod
The paymentmethod is attached to the Customer
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)
What does your client side code look like?
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()]);
}
Okay and your JS code?
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");
}
And are you seeing you clientsecret in that log?
no
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
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
error_log($jsonStr)
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
Yeah you likely want to add an error_log to ensure your sub is actually getting created
really good error_log for develop debug, let me create one cus in mode test maybe is this issue
nothing work still
please which is the minimun data for create one subscription ?
bismark had to head out, but i'm hopping in - are you seeing the requests to create a subscription in your dashboard request logs?
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
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)?
yes I work in this, please
what seems strange to me is that I do not receive any errors in stripe dashborad logs
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?
$stripe->subscriptions->create which is the minimal data to create this subscription please?
yes my server works good without subscription see pi_3L3qhgHHulAmiNnD0CWyLAPm
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
but when I try to create subscription not work
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)
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
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)
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 ?
You can read more about there here: https://github.com/stripe/stripe-php/wiki/Migration-to-StripeClient-and-services-in-7.33.0
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 ?
That's specifically for Stripe Tax - is that something you need for your integration?
yes I implement really good all
how can I add to stripe element apple pay ? option ? here is my implementation complete https://www.derechoteca.com/oferta/37/507468/ec9b48f47a49429baed2bef65cbf4258
If you're implementing Stripe Tax you should really read through this documentation: https://stripe.com/docs/billing/taxes/collect-taxes
To activate apple pay you need to register an apple pay web domain: https://stripe.com/docs/stripe-js/elements/payment-request-button?html-or-react=html#verifying-your-domain-with-apple-pay
Hi @worldly ravine I'm taking over this thread
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.
Did you pass the setup_future_usage param when creating the PaymentIntent?
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.'],
]);
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.
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 ?
Just want to understand the question, you want to display localized message to your customer based on the paymentIntent status?
yes I get his from your https://stripe.com/docs/payments/quickstart checkout.js
I really want to change these messages to Spanish, is there a problem with it for stripe element or should they be in English?
Of course you can display the message in the language that is most suitable to your customer.
thank you
how can I change your desing of stripe element ?
for something more minimal
You can provide the locale param when initializing the Stripe.js (https://stripe.com/docs/js/appendix/supported_locales)
Also you can change the appearance of the PaymentElement via appearance API (https://stripe.com/docs/js/elements_object/update#elements_update-options-appearance)
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.
I try, thanks , another ask , plase and how can I add more methods to stripe element ?
There are only a few payment methods that support subscription, you can find them here https://stripe.com/docs/payments/payment-methods/integration-options
But first you need to turn on these payment method in your Dashboard first.
in which place can I turn please
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
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.
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.
but maybe you can show me in which place of file can I need to do this change? I can t found where
Are you using PaymentIntent or SetupIntent anywhere in your application?
Im sorry how can I see this ... which is the difference
Just search PaymentIntent and SetupIntent in your source code.
I m using subscription with stripe element
'clientSecret' => $subscription->latest_invoice->payment_intent->client_secret,
I mean payment_intent rigth ?
Got it. Since you are not using PaymentIntent or SetupIntent you can ignore the message for now.
For subscriptions, you can go to https://dashboard.stripe.com/settings/billing/invoice to set the payment methods that you want to provide to your customers for subscription.
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Alternatively you can also use https://stripe.com/docs/api/subscriptions/create?lang=php#create_subscription-payment_settings-payment_method_types to limit the list of payment methods that you want to provide.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
let see i you are understand me, please jack
as you can see here https://www.derechoteca.com/oferta/37/507468/ec9b48f47a49429baed2bef65cbf4258 I have enable just CARD and Google Pay, how can I enable more options ?
Can I check if you have
- Enabled the payment methods in your Dashboard (
https://dashboard.stripe.com/settings/payment_methods) - Added the payment methods for invoice? ( https://dashboard.stripe.com/settings/billing/invoice )
- Enabled the payment methods in your Dashboard. All enabled Jack
- 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 ?
Can you share with me your merchant ID? you can find it from the Stripe Dashboard -> Settings ->Account Details
Yes, give me a sec, let me take a look
thanks
The ACH Direct Debit is not enabled.
This is another payment method available in US for subscription.
They either don't support subscription or not available in US.
Alipay is invite only, and Apple Pay supports subscription (except Mexico)
You need to verify your domain in order to enable Apple Pay https://support.stripe.com/questions/enable-apple-pay-on-your-stripe-account
Find help and support for Stripe. Our support center provides answers on all types of situations, including account information, charges and refunds, and subscriptions information. Get your questions answered and find international support for Stripe.
ok how can I enable ACH Direct Debit ?
https://dashboard.stripe.com/settings/payment_methods visit this page and click on the Turn on button right besides ACH Direct Debit.
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
I add but now show in my landingpage
i need to add some code in stripe element ? maybe ?
Can you create a new subscription and see if the new payment method is available in payment element?
as you can see just card and google https://www.derechoteca.com/oferta/37/507468/ec9b48f47a49429baed2bef65cbf4258
i need to add some code in stripe element ? maybe ?
to show apply and ach
ACH is for customers in US, but your customer's billing address is a non-US address.
ok, thank you , please I need to stripe element require name on card this is possbile ?
The name is not a mandatory field for card payment, you can build your own field to collect your customer's name.
and can I mandatory field ? in stripe element
i mean, make this name field must be required ?
I'm afraid that there's no option to make name field mandatory in PaymentElement.
how can I add with the same css style my own field sorry ?
You can't set css to the payment element, but you can use the appearance API to customize the look and feel https://stripe.com/docs/elements/appearance-api