#Sarvesh

1 messages · Page 1 of 1 (latest)

polar gobletBOT
tight violet
#

I have few queries with connected account direct charges apis
$paymentIntent = PaymentIntent::create([
'payment_method_types' => ['card'],
'payment_method' => 'pm_card_bypassPending',
'amount' => 700, //$eventRegData->total_amount,
'currency' => 'usd',
'application_fee_amount' => 123, //$eventRegData->platform_fee,
'transfer_group' => 'directCharges1',
'confirm' => true,
], ['stripe_account' => $hostData->stripe_id]);

#

in paymentIntent response which fields I need to check to update payment status is done?

#

or I will receive webhook notification?

faint bluff
tight violet
#

ok, but if i not subscribed to webhook then also from the paymentIntent response I will check few fieldset and update the payment status right?

#

or webhook is needed?

#

I should rely on paymentIntent response or webhook response?

faint bluff
#

We recommend to subscribe to webhook events as well in case

  • if your request is not able to get response, you can still get outcome via webhook
  • if the asynchronous payment method is used and the payment outcome will be posted via webhook
tight violet
#

ok where to subscribe for this webhook?

#

do you have link?

faint bluff
faint bluff
#

Yes, this is similar. This code is an example for your reference.

tight violet
#

ok

#

how i can build form to get card / bank details from user ?

#

and then split payment and call paymentintent api?"

faint bluff
#

and then split payment and call paymentintent api?"
Can you explain more on what you want to achieve?

tight violet
#

yes, goal is something like,
when user register for the event, we want to show the form to fill up card / bank details on our site and we will post it to API. We do not want to redirect user to Stripe page to fillup card/bank details and pay from there. So what could be the solution for this case

faint bluff
tight violet
#

ok great, can we get that form HTML/JS to accept credit/debit card or US Bank accounts only?

#

"stripe/stripe-php": "^9.4", we alredy installed via composer

pulsar plover
#

Hi! I'm taking over this thread.

tight violet
#

Hi Soma
Yes this is fine. I am asking that is there a customize form to download available with all needed payment menthod fields like credit/debit card fieldset, bank account field set etc?

#

with their proper inputs validations Javascript?

pulsar plover
#

If you are using the Payment Element, this is built in by default.

  1. Create the PaymentIntent on the backend and set the payment method you want
  2. Then on the frontend the Payment Element will automatically display the correct UI with all the required fields
tight violet
#

i see, good, let me check this

pulsar plover
tight violet
#

ok
$stripe->paymentIntents->create(
[
'amount' => 1099,
'currency' => 'usd',
'automatic_payment_methods' => ['enabled' => true],
]
);

So 'automatic_payment_methods' => ['enabled' => true], will generate a form above shown?

pulsar plover
#

'automatic_payment_methods' => ['enabled' => true] means that all payment method activated in your dashboard will be shown in the Payment Element form.

tight violet
#

Payment Element form how to create?

tight violet
#

client secret used in JS and will be visible in page view source will not security problem

#

?

pulsar plover
#

No issue, that's our recommended implementation:

  • Create the PaymentIntent on the backend
  • Send the client_secret to the frontend
  • The use the client_secret to mount the Payment Element
tight violet
#

ok

#

suppose I need to pay amount
$12.5 for event registration charges to connected event host account and internally with payment intent we will split website charges 1.5 to main stripe account then How I need to send these amounts to payment intent object?
12.5 x100? = 1250?
1.5 x100 = 150?

pulsar plover
#

So you want to charge the customer $12.5, and then you want the platform account to keep $1.5?

tight violet
#

yes

pulsar plover
#

The the amount to charge is 12.5 * 100 = 1250. Then to send money to the connected account, you have to decide how you want to do it. You have three options that are explained here: https://stripe.com/docs/connect/charges

tight violet
#

ok so for each amount we need to multiply by 100 before sending to api request right?

pulsar plover
tight violet
#

ok we will only receive US dollars only as customer base from USA only

pulsar plover
#

Then yes it's just $amount x 100.

tight violet
#

ok thanks

#

Now I will try to build the payment elements form as per above documentation

#

next question is regarding the webhook response from payment intent transactions, which fields we need to look to decide whethere payment success/fail/ any errors etc.

pulsar plover
tight violet
#

ok, good

#

what are the Stripe payment processing charges for payment intents?
We need to include that amount in our event registration fee so that it will be taken from the customers

#

I hope it must be some %% on the event fee

pulsar plover
#

You can learn more about our pricing here: https://stripe.com/pricing
And if you want to know the exact Stripe fee for a specific PaymentIntent:

tight violet
#

So from first link
3% for cards issued outside India
So can we save this 3% as stripe processing fee in our project setting and our event fee say $10 then calculate 10*3%=0.03
so total amount to pay $10.03 for end customers?

#

including stripe fee

pulsar plover
#

If you create a PaymentIntent for $10, the customer will pay exactly $10 and the Stripe fee is included in this, so you business will get ~$9.70
If you want your business to get exactly $10, then yes you would need to increase your price a little.

#

But note that the Stripe fee can change depending on the type of card, on the payment method used.

tight violet
#

ok

#

Stripe fee can change depending on the type of card, on the payment method used.
where it is mentioned?

final narwhal
#

👋 taking over for my colleague. Let me catch up.

#

if you need specific charge fees you can visiting https://stripe.com/pricing or contact https://support.stripe.com/?contact=true for more info

tight violet
#

ok

final narwhal
#

let me know if you need any more help

tight violet
#

yes
The Payment Element contains an iframe that securely sends the payment information to Stripe over an HTTPS connection. The checkout page address must also start with https:// rather than http:// for your integration to work.
So this will shows a form and get submitted to Stripe without API call?

final narwhal
#

yes true

tight violet
#

but what will heppen after form is posted? user will stay on same site or redirect to Stripe?

final narwhal
#

if you're using PaymentElement on your site, redirection will only happen when an action (e.g. 3DS) is needed and you can specify where to redirect after success

tight violet
#

ok I have this object created

$paymentIntent = PaymentIntent::create([
'payment_method_types' => ['card'],
'payment_method' => 'pm_card_bypassPending',
'amount' => 700, //$eventRegData->total_amount,
'currency' => 'usd',
'application_fee_amount' => 123, //$eventRegData->platform_fee,
'transfer_group' => 'directCharges1',
'confirm' => true,
], ['stripe_account' => $hostData->stripe_id]);

So If I want to take card details from user then I need to add
automatic_payment_methods' => ['enabled' => true], ??

final narwhal
#

no not necessary

#

since already you specified payment_method_types

tight violet
#

ok, I am still not understood correctly following scenario

  1. on our payment info page we will show payment summary e.g.
    Event fee: $10
    Platform (website) charges: $0.5
    Stripe charges : 0.5
    Total to Pay: $11
    and below of this we want to show the a form on our website (maybe without Iframe from stripe) to select the payment methods (Card or Bank Transfer)
    and based on select the form fields will change and user will fill the card details or bank account details and on Submit we will call our function to set the
    amount => 1000
    'application_fee_amount' => 50
    stripe_account' => $hostData->stripe_id
    and send API requests
#

and we should get the response back from request and also from the webhook subscribed to update the payment status in our database

#

so in above case, we want to use HTML / JS form elements based on payment method selected by user instead of creating our own form

#

is this possible? can we get readymade form code ?

final narwhal
#

just give me a minute to read through

tight violet
#

sure

final narwhal
#

and below of this we want to show the a form on our website (maybe without Iframe from stripe) to select the payment methods (Card or Bank Transfer)
if you don't want to use Stripe Elements you would have to worry about being PCI compliance and about how to create the Payment Methods yourself, that's a big hassle that I don't really recommend you doing

tight violet
#

ok, so you suggest to use I frame with form elements ?

#

but in that case how we can attach the payment intentent split payment to main and connected accounts?

final narwhal
#

that has nothing to do with the frontend code

#

depending on your scenario

tight violet
#

yes but this Creating direct charges I need to create object first with all split payment and then ask user to fill up the payment form inside the iframe which we get submitted to stripe?

#

how strip will know which amount to pay to which accounts ?

obsidian glen
#

a Direct Charge is for doing one payment with just your platform and a connected account (the connected account gets most of the money, and you take e.g. a 10% amount for yourself). It doesn't involve multiple accounts.

tight violet
#

yes, do not need multiple accounts in our case, only 2 main account (to get some %) and connected account with major amount

#

whole picture is not getting cleared with iframe integration how I can call the api? to split some amount to main account and connected account

#

or is thre a way to create direct charges object and redirect user to Stripe to fill the card/bank details on stripe page and then you will send it back to us success/error info?

#

?

obsidian glen
obsidian glen
tight violet
#

ok checking the last url

#

https://stripe.com/docs/connect/enable-payment-acceptance-guide?platform=web&ui=checkout#create-checkout-session
This is the correct workflow as explained in the diagram, we want to implement

The checkout.html
<html>
<head>
<title>Checkout</title>
</head>
<body>
<form action="/create-checkout-session" method="POST">

HOW FORM ELEMENTS SHOW HERE BASED ON CARD/BANK SELECTED BY END USER

  <button type="submit">Pay</button>
</form>

</body>
</html>

Facilitate direct payments between other businesses and their own customers.

#

HOW FORM ELEMENTS SHOW HERE BASED ON CARD/BANK SELECTED BY END USER in checkout.html?

obsidian glen
#

not sure what you mean

#

you're talking about Checkout, which is a hosted Stripe page.

#

on your own site, you simply have a button

#

the user clicks the button, and they are redirected to Stripe, and that's where they enter their payment information, and then are redirected back to you.

tight violet
#

ok got it now
but the object we created
$paymentIntent = PaymentIntent::create([
'payment_method_types' => ['card'],
'payment_method' => 'pm_card_bypassPending',
'amount' => 700, //$eventRegData->total_amount,
'currency' => 'usd',
'application_fee_amount' => 123, //$eventRegData->platform_fee,
'transfer_group' => 'directCharges1',
'confirm' => true,
'automatic_payment_methods' => ['enabled' => true],
], ['stripe_account' => $hostData->stripe_id]);
when to post it to Stripe? with above checkout form post or when?

obsidian glen
#

that code is not using Checkout so it's something entirely different.

tight violet
#

how stripe will know the how much application fee amount to transfer to other account?

#

can we do a quick call? its long time we are dicussing on this flow

obsidian glen
#

so first you have to decide which flow you're going to use, the hosted Checkout page, or your own page.

obsidian glen
tight violet
#

yes, but along with that I need to update the object with user inputs card / bank details right? so that you will charge money from that card/bank account

#

so that I want to show a form with card / bank input fields and on form post we will send all details together to API

obsidian glen
#

it depends. Are you using Checkout or not?

#

again though, it's all in the guide

tight violet
#

its not checkout, custom api calls we need to do

obsidian glen
#

are you sure you "need" to do custom API calls? do you have a specific reason for not using Checkout? Do you understand the difference and extra dev work in building your own payment form directly?

tight violet
#

$intent = # ... Fetch or create the PaymentIntent;
what is mean by Fetch or create the PaymentIntent;?

#

<?php
$intent = # ... Fetch or create the PaymentIntent;
?>
...
<form id="payment-form" data-secret="<?= $intent->client_secret ?>">
<div id="payment-element">
<!-- Elements will create form elements here -->
</div>

<button id="submit">Submit</button>
</form>
...

obsidian glen
#

so now in this step, you want to set $intent to be that PaymentIntent object you created

#

is that clear?

tight violet
#

yes, going with this direction

obsidian glen
#

@tight violet any further questions or can I close this thread for now?

tight violet
#

Form is showing only submit button from $intent.

#

form elements does not loaded

obsidian glen
#

what is in the console logs tab, any errors?

tight violet
#

no errors

obsidian glen
#

share the exact code you're using

tight violet
#

Stripe::setApiKey(config('services.stripe.stripeSecret'));
$paymentIntent = PaymentIntent::create([
'payment_method_types' => ['card'],
'payment_method' => 'pm_card_bypassPending',
'amount' => 700, //$eventRegData->total_amount,
'currency' => 'usd',
'application_fee_amount' => 123, //$eventRegData->platform_fee,
'transfer_group' => 'directCharges1',
'confirm' => true,
//'automatic_payment_methods' => ['enabled' => true],
], ['stripe_account' => 'acct_1LxWk2PBvk5urIAm']);

<form id="payment-form" data-secret="<?= $paymentIntent->client_secret ?>">
<div id="payment-element">
<!-- Elements will create form elements here -->
</div>

<button id="submit">Submit</button>
</form>

obsidian glen
#

where is your Javascript?

#

did you actually write the frontend code that create the Stripe Element?

tight violet
obsidian glen
#

you need to include that, and write a bunch of your own code, yes....

tight violet
#

ok

tight violet
#

<script src="https://js.stripe.com/v3/"></script>
<script>
const stripe = Stripe('pk_test_51LcWQoALTlZ8nxc3GJK8QkvCP3La9KU8BHrcFljOTyJpWFMnzP9l9JAwelvy6IvdmdOddsZx4YzENuYnsQTRLO6200mbv2lMGT', {
stripeAccount: 'acct_1LxWk2PBvk5urIAm'
});
//const stripe = Stripe('pk_test_51LcWQoALTlZ8nxc3GJK8QkvCP3La9KU8BHrcFljOTyJpWFMnzP9l9JAwelvy6IvdmdOddsZx4YzENuYnsQTRLO6200mbv2lMGT');
const options = {
clientSecret: 'sk_test_51LcWQoALTlZ8nxc3bpx4OjMu2WedesCask1c8que7gMVZBml4A9RAo6TXimQdFcU5LJuyZzlbJzRBwiDudItKqkR00ZpMKJISz',
// Fully customizable with the Appearance API
appearance: {/.../},
};
// Set up Stripe.js and Elements to use in checkout form using the client secret
const elements = stripe.elements(options);
// Create and mount the Payment Element
const paymentElement = elements.create("payment");
paymentElement.mount("#payment-element");
</script>

This is provided in JS and your JS is also included and loaded properly before the JS code
still form elements are not visible.

#

got 1 error in console

#

Invalid value for elements(): clientSecret should be a client secret of the form ${id}secret${secret}. You specified: sk_test_51LcWQoALTlZ8nxc3bpx4OjMu2WedesCask1c8que7gMVZBml4A9RAo6TXimQdFcU5LJuyZzlbJzRBwiDudItKqkR00ZpMKJISz.

#

now shown the form

#

after fixed above error

#

is there any css to load for form?

solar pecan
#

Hey! Taking over for my colleague. Let me catch up.

tight violet
#

what will be the next step?
Can I set form action="my-custom-action" and call stripe api or this form will get directly posted to Stripe and return response to Return URL specified?

solar pecan
#

Sorry for my late reply

solar pecan
solar pecan
tight violet
#

ok

#

payment_intent_unexpected_state
The PaymentIntent’s state was incompatible with the operation you were trying to perform.

#

getting this error now

#

type: 'invalid_request_error', code: 'payment_intent_unexpected_state',

solar pecan
#

However, I may invite to to complete a separate sample project that accept Card Payment aside, then try working on your target project. You can follow/download this full Quickstart and try to understand each step:
https://stripe.com/docs/payments/quickstart?lang=node

tight violet
#

transation is not failing, on stripe it is showing Succeeded pi_3Lxs0BPBvk5urIAm0h5mUD1c

#

in console it is getting error

solar pecan
#

You need to create new PaymentIntent for each customer purchase

#

Tha PaymentIntent is already confirmed and succeeded. You need to pass a client_secret of new PaymentIntent to make a new attempt

tight violet
#

ok, and I can send the my eventId and user id along with request which I can get back in return response in success / fail case so that I can update that record in database?

#

also in above screenshot I can not see the Card / Bank details boxes to switch? I need to enabled bank account from my dashboard so it will get visible on top o form?

dusty oyster
#

Hi there 👋 I'm jumping in as my teammate needs to step away soon.

dusty oyster
dusty oyster
tight violet
#

$paymentIntent = PaymentIntent::create([
//'payment_method_types' => ['card'],
'payment_method' => 'pm_card_bypassPending',
'amount' => 800, //$eventRegData->total_amount,
'currency' => 'usd',
'application_fee_amount' => 244, //$eventRegData->platform_fee,
'transfer_group' => 'directCharges1',
'confirm' => true,
'automatic_payment_methods' => ['enabled' => true],
'return_url' => 'http://localhost:8000/athlete/payment',
], ['stripe_account' => 'acct_1LxWk2PBvk5urIAm']);

I can send the eventId and use id along with request which I can get back in return response in success / fail case so that I can update that record in database?

dusty oyster
#

That request won't give you an Event ID, Events are the objects that Stripe sends to your endpoints if you set up a webhook endpoint.
https://stripe.com/docs/api/events

I'm also not sure what you're referring to by user ID, do you mean the ID of the Customer object?

The request that you're showing will return a Payment Intent, and that Payment Intent will have an ID that you can use to reference it later.
https://stripe.com/docs/api/payment_intents/object#payment_intent_object-id

tight violet
#

no I am not talking about that event
Can I send some custom fields with the paymentIntegent request to Stripe? e.g loggedin userid on our website, and productId or eventId he is going to pay for

#

so that I will get those custom fields back in the response to track the response or webhook and update the data in our database

dusty oyster
tight violet
#

ok