#jayvir_code

1 messages ¡ Page 1 of 1 (latest)

errant cipherBOT
#

👋 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/1369290701870989326

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

urban glade
#

hi @fast knot

fast knot
#

hi there!

urban glade
#

static async StripeRequestWithApplicationFeeAch(
amount,
paymentId,
connectedAccountId,
secretKey,
serviceFee,
customerId,
metadata,
) {
try {
let formBody =
amount=${amount}& +
currency=usd& +
confirm=true& +
customer=${encodeURIComponent(customerId)}& +
payment_method=${encodeURIComponent(paymentId)}& +
payment_method_types[]=us_bank_account& +
application_fee_amount=${serviceFee}& +
on_behalf_of=${encodeURIComponent(connectedAccountId)};

  if (metadata && typeof metadata === 'object') {
    for (const key in metadata) {
      const encodedKey = encodeURIComponent(key);
      const encodedValue = encodeURIComponent(metadata[key]);
      formBody += `&metadata[${encodedKey}]=${encodedValue}`;
    }
  }

  const url = 'https://api.stripe.com/v1/payment_intents';

  const apiCall = await axios({
    method: 'post',
    maxBodyLength: Infinity,
    url: url,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      Authorization: `Bearer ${secretKey}`, // Platform secret key
      'Stripe-Account': connectedAccountId, // Scope request to connected account
    },
    data: formBody,
  });

  return apiCall?.data || {};
} catch (error) {
  console.error(error?.response?.data || error, 'StripeRequestWithApplicationFee');
  return { error: error?.response?.data || error };
}

}

{
error: {
message: "The 'on_behalf_of' param cannot be set to your own account.",
param: 'on_behalf_of',
request_log_url: 'https://dashboard.stripe.com/acct_1PbaxeJRoJfA1S16/test/logs/req_ycn9MQglFzR1jI?t=1746534693',
type: 'invalid_request_error'
}
} StripeRequestWithApplicationFee

fast knot
#

the error message you shared is pretty clear. what's your question?

urban glade
#

i want to deduct money with ach using setup intent

#

all should happen on connected account
just pass application fee in platform account

fast knot
#

sure

#

did you read the error message? you just need to remove on_behalf_of from your request.

urban glade
#

@fast knot removed payment show success ?

#

where can i see payment transaction ?

#

pi_3RLkjyJRoJfA1S162Ao6zjHx

fast knot
#

sorry I don't understand your question, can you clarify exactly what you are trying to do?

urban glade
#

where can i see payment happened with ach ?

fast knot
#

for you as the platform? using code or the dashboard?

urban glade
#

i am using code

#

nodejs

fast knot
#

you would setup a connect webhook endpoint on your platform, and listen to the payment_intent.succeed event.

urban glade
#

payment_intent.succeed - what it will provide for ach ?

fast knot
#

what do you mean by "provide for ach"?

urban glade
#

lets again start
i have done payment from below code

static async StripeRequestWithApplicationFeeAch(
amount,
paymentId,
connectedAccountId,
secretKey,
serviceFee,
customerId,
metadata,
) {
try {
let formBody =
amount=${amount}& +
currency=usd& +
confirm=true& +
customer=${encodeURIComponent(customerId)}& +
payment_method=${encodeURIComponent(paymentId)}& +
payment_method_types[]=us_bank_account& +
application_fee_amount=${serviceFee}&;

  if (metadata && typeof metadata === 'object') {
    for (const key in metadata) {
      const encodedKey = encodeURIComponent(key);
      const encodedValue = encodeURIComponent(metadata[key]);
      formBody += `&metadata[${encodedKey}]=${encodedValue}`;
    }
  }

  const url = 'https://api.stripe.com/v1/payment_intents';

  const apiCall = await axios({
    method: 'post',
    maxBodyLength: Infinity,
    url: url,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      Authorization: `Bearer ${secretKey}`, // Platform secret key
      'Stripe-Account': connectedAccountId, // Scope request to connected account
    },
    data: formBody,
  });

  console.log(apiCall?.data,'apiCall?.data')

  return apiCall?.data || {};
} catch (error) {
  console.error(error?.response?.data || error, 'StripeRequestWithApplicationFee');
  return { error: error?.response?.data || error };
}

}

#

i am not able to see amount in stripe dashboard
where to see that payment id ?

errant cipherBOT
fast knot
#

why are you not using Stripe SDK to make the API request?

#

but to answer your question: when you create the PaymentIntent, you'll get the ID in the API response.

urban glade
#

i am using both sdk & api both

fast knot
#

I recommand using our SDK instead of manually calling the API.

alpine orchid
#

I'm also a little concerned you appear to be making requests with a secret key from your front end / client application, which is not secure

#

Those requests (to the payment intents API using your secret key) need to be happening in a secure server environment

urban glade
#

PaymentIntent was successful: {
id: 'pi_3RLlBaJRoJfA1S161GMbjGSm',
object: 'payment_intent',
amount: 21246,
amount_capturable: 0,
amount_details: { tip: {} },
amount_received: 21246,
application: 'ca_NopZt5hgNQIKQCGZble82jThvsAFqm9k',
application_fee_amount: 600,
automatic_payment_methods: null,
canceled_at: null,
cancellation_reason: null,
capture_method: 'automatic_async',
client_secret: 'pi_3RLlBaJRoJfA1S161GMbjGSm_secret_mvF4ZY21qjXbpqPGufJElCOwz',
confirmation_method: 'automatic',
created: 1746536726,
currency: 'usd',
customer: 'cus_SGHBY33m0urXib',
description: null,
invoice: null,
last_payment_error: null,
latest_charge: 'py_3RLlBaJRoJfA1S161WGtWLNE',
livemode: false,
metadata: {
sketchplayBucks: '0',
discountCodeAmount: '0',
orgId: '30',
paidAmount: '212.46',
eventInsuranceTotal: '0',
AthName: 'Test New',
stripeFees: '6.46',
serviceFee: '12.46',
event: '11322',
insuranceGapAmount: '0',
orgName: 'Zoombi',
insuranceAmount: '0',
originalEventAmount: '200',
sketchplayFee: '6',
email: 'tsp44414@yopmail.com',
AthEmail: 'tsp44414@yopmail.com',
totalCost: '212.46',
discountCode: ''
},
next_action: null,
on_behalf_of: null,
payment_method: 'pm_1RLlBYJRoJfA1S16CGmw4tZq',
payment_method_configuration_details: null,
payment_method_options: {
us_bank_account: { mandate_options: {}, verification_method: 'automatic' }
},
payment_method_types: [ 'us_bank_account' ],
processing: null,
receipt_email: null,
review: null,
setup_future_usage: null,
shipping: null,
source: null,
statement_descriptor: null,
statement_descriptor_suffix: null,
status: 'succeeded',
transfer_data: null,
transfer_group: null,
charges: {
object: 'list',
data: [ [Object] ],
has_more: false,
total_count: 1,
url: '/v1/charges?payment_intent=pi_3RLlBaJRoJfA1S161GMbjGSm'
}
}

#

@alpine orchid

async StripeRequestWithApplicationFeeAch(
amount,
paymentId,
connectedAccountId,
secretKey,
serviceFee,
customerId,
metadata,
) {
try {
const { stripe, config } = await this.getStripeInstance();

  const paymentIntent = await stripe.paymentIntents.create(
    {
      amount: amount,
      currency: 'usd',
      confirm: true,
      customer: customerId,
      payment_method: paymentId,
      payment_method_types: ['us_bank_account'],
      application_fee_amount: serviceFee,
      metadata: metadata || {},
    },
    {
      stripeAccount: connectedAccountId, // Connect platform account context
    },
  );

  console.log(paymentIntent, 'paymentIntent');
  return paymentIntent;
} catch (error) {
  console.error(error, 'StripeRequestWithApplicationFee');
  return { error: error };
}

}

i used sdk now

#

i am not able to view the payment happened
i used ach (stripe)

#

where to check ach payment ?

alpine orchid
#

Is that instance of stripe being initialized on your server, or still in the client-side application?

#

i am not able to view the payment happened
i used ach (stripe)
where to check ach payment ?
What do you mean? What are you trying to do?

urban glade
#

everything i am sending is on server side

alpine orchid
#

Ok, and what exactly do you need help with about those ACH payments?

urban glade
#

i am not able to see the payment in stripe dashboard ?

#

where can i see that

#

example: pi_3RLlBaJRoJfA1S161GMbjGSm

alpine orchid
#

This is a direct charge request to a standard connected account