I am using Node with Firebase Cloud Functions to trigger the Auth & Capture of Direct Charges with Stripe Connect.
First I create the charge, not capturing it:
const charge = {
capture: false,
amount: 1000,
currency: "eur",
source: token,
metadata: {order_id: rentID, some: "foo"},
};
return stripe.charges.create(charge, {stripe_account: customAccount} )
Everything goes smoothly, and I get the charge object from the callback:
ch_1BGmUCLdU1UUJ0JXgMKI7Q:
amount: 1000
amount_refunded: 0
application: "some"
captured: false
created: 1508928708
currency: "eur"
id: "ch_1BGmUCLdU1UUJ0JXgMKI7Qet"
livemode: false
metadata: {}
object: "charge"
outcome: {}
paid: true
refunded: false
refunds: {}
source: {}
status: "succeeded"
I also get the charge from the appropriate webhook:
-KxI9Dk-LVvM8Wth1TwC: {
api_version: "2017-08-15"
created: 1508928708
data:
object:
amount: 1000
amount_refunded: 0
application: "some"
captured: false
created: 1508928708
currency: "eur"
id: "ch_1BGmUCLdU1UUJ0JXgMKI7Qet"
livemode: false
metadata: {}
object: "charge"
outcome: {}
paid: true
refunded: false
refunds
source
status: "succeeded"
id: "evt_1BGmUCLdU1UUJ0JXPRl5bvCx"
livemode: false
object: "event"
pending_webhooks: 1
request
id: "req_4sR247IPJCeXMU"
type: "charge.succeeded"
}
However, when I want to capture the charge using
return stripe.charges.capture("ch_1BGmUCLdU1UUJ0JXgMKI7Qet", {amount: 1000})
I get the issue:
Error: No such charge: ch_1BGmUCLdU1UUJ0JXgMKI7Qet
It is also weird because in my Stripe Dashboard I cannot see the capture recorded in the test/event category.
Any idea what causes this?
This issue is related to this one. The charge is not recognized because it is not recorded in the platform account, but in the connected account directly.
So in order to capture the charge, this is what to do:
stripe.charges.capture(transactionID, {stripe_account: connectedAccount})