#prabhawsotiebpearls_19934
1 messages · Page 1 of 1 (latest)
app.use('/stripe/webhook-connect', bodyParser.raw({ type: 'application/json' }));
const stripePayload = (req as any).rawBody || req.body;
event = await this.stripe.webhooks.constructEvent(
stripePayload,
signature.toString(),
webhookSecret,
);
} catch (err) {
console.log(`Webhook signature verification failed.`, err);
return err;
}
why i am geting this error my code is
const paymentConfig = {
amount: invoice.itemTotal * 100,
currency: 'aud',
payment_method_types: ['card'],
payment_method: cardId,
confirm: true,
capture_method: 'automatic',
receipt_email: user.email,
customer: user.pioneerId.toString(),
shipping: {
address: {
city: null,
country: 'Australia',
line1: data.address.addressLineOne,
line2: data.address.addressLineTwo,
postal_code: data.address.postCode,
state: data.address.state,
},
name: ${user.firstName} ${user.lastName},
phone: user.mobile ? user.mobile : '',
},
application_fee_amount:
(invoice.ycCommission +
invoice.stripeFee +
invoice.gst +
invoice.shippingCost) *
100,
transfer_data: {
destination: bankdetails.stripeConnectId,
},
};
hello, it looks like you're using Express.js? Do you have any middleware processing response prior to this line?
app.use('/stripe/webhook-connect', bodyParser.raw({ type: 'application/json' }));
@Controller('stripe')
export class StripeController {
private stripe: Stripe;
constructor(private readonly webhookService: WebhookService) {}
@Post('/webhook-connect')
async stripeWebhookConnect(@Req() req) {
const webhookSecret = process.env.STRIPE_WEBHOOK_CONNECT_SECRET;
return this.webhookService.processWebHookResponse(req, webhookSecret);
}
}
reques is up to
const stripePayload = (req as any).rawBody || req.body;
event = await this.stripe.webhooks.constructEvent(
stripePayload,
signature.toString(),
webhookSecret,
);
} catch (err) {
console.log(Webhook signature verification failed., err);
return err;
}
constructEvent through error
message: 'No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe?
if you log the Payload, what do you get?
{
id: 'evt_1OaATRJqZtD0evYRcVTJt8L5',
object: 'event',
api_version: '2022-11-15',
created: 1705641517,
data: {
object: {
id: 'fee_1OaATPQuqgrPLaPyib97pH7B',
object: 'application_fee',
account: 'acct_1OV9H0QuqgrPLaPy',
amount: 4400,
amount_refunded: 0,
application: 'ca_P6hV3uj4ROv5vieraA7Uqe5vzIooqhVz',
balance_transaction: 'txn_1OaATRJqZtD0evYRfGbXO7LY',
charge: 'py_1OaATOQuqgrPLaPyeBEVFP4u',
created: 1705641515,
currency: 'aud',
livemode: false,
originating_transaction: 'ch_3OaATOJqZtD0evYR0frQf8iN',
refunded: false,
refunds: [Object]
},
previous_attributes: {}
},
livemode: false,
pending_webhooks: 1,
request: { id: null, idempotency_key: null },
type: 'application_fee.created'
}
{
id: 'evt_3OaATOJqZtD0evYR0vPaXklP',
object: 'event',
api_version: '2022-11-15',
created: 1705641515,
data: {
object: {
id: 'pi_3OaATOJqZtD0evYR0U8IPPFF',
object: 'payment_intent',
amount: 22000,
amount_capturable: 0,
amount_details: [Object],
amount_received: 22000,
application: null,
application_fee_amount: 4400,
automatic_payment_methods: null,
canceled_at: null,
cancellation_reason: null,
capture_method: 'automatic',
client_secret: 'pi_3OaATOJqZtD0evYR0U8IPPFF_secret_FVj7sNJogIHDFbec4Yq20BxG6',
confirmation_method: 'automatic',
created: 1705641514,
currency: 'aud',
customer: '6549d47f8db7920f83ffd476',
description: null,
invoice: null,
last_payment_error: null,
latest_charge: 'ch_3OaATOJqZtD0evYR0frQf8iN',
livemode: false,
metadata: {},
next_action: null,
on_behalf_of: null,
payment_method: 'card_1OaATNJqZtD0evYRgffpiExZ',
payment_method_configuration_details: null,
payment_method_options: [Object],
payment_method_types: [Array],
processing: null,
receipt_email: 'binod.ebpearls@gmail.com',
review: null,
setup_future_usage: null,
shipping: [Object],
source: null,
statement_descriptor: null,
statement_descriptor_suffix: null,
status: 'succeeded',
transfer_data: [Object],
transfer_group: 'group_pi_3OaATOJqZtD0evYR0U8IPPFF'
}
},
livemode: false,
pending_webhooks: 1,
request: {
id: 'req_EE34MyuwrSCfVp',
idempotency_key: '5ac44d02-dde4-4701-9082-a919273b01f3'
},
type: 'payment_intent.succeeded'
}
how are you processing the request before passing it in here : async stripeWebhookConnect(@Req() req) { ? Which framework are you using?
nestjs
app.use('/stripe/webhook-connect', bodyParser.raw({ type: 'application/json' }));
if i look at the nestJS docs, the raw request body should be a Buffer when accessed : https://docs.nestjs.com/faq/raw-body - you'll probably want to follow the guide for how to implement it.
Nest is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with TypeScript and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Reactive Programming).
it's working on local computer but in server it's throwing errors
is the webhook secret key correct then? Typically when you migrate, you would have created a new webhook endpoint which is using a different webhook secret
yes it's correct i create new secret for that\ with deployment url