Stripe Payout - How to match statement text on bank account to Payout? - stripe-payments

I have a case where I should check the Stripe Payouts API if a new Stripe Payout received at my bank account. The statement text at the bank is in this format:
STRIPE Y1O2A2
or
STRIPE A7O4X2
It is "STRIPE" + a random string.
The Stripe Payouts API result object has a field called "statement_descriptor", but it is empty. I don't know how to assign the the payout received at my bank to a result of the payout API.
Any ideas or suggestions?

Thanks to the advice of #karllekko's command in my question I solved it this way:
$date_money_arrived_at_bank = strtotime('2020-08-31 02:00:00');
$amount_arrived_at_bank_in_cents = 2939;
$x = $stripe->payouts->all(
[
'status' => 'paid',
'arrival_date' => $date_money_arrived_at_bank
]
);
if($x->date[0]->amount == $amount_arrived_at_bank_in_cents) {
// this is your payout
}
I'm am in CET time so I had to set the time UTC+2.
EDIT: This don't work if you have 2 payouts at the same day with the same amount.

Related

How to test recurring payment on stripe subscription for due bill?

I have created subscription using stripe api for 1 month interval.
const subscription = await stripe.subscriptions.create(
{
customer: customer.id,
items: [
{
price: productPrice.id,
},
],
// payment_behavior: 'default_incomplete',
expand: ['latest_invoice.payment_intent'],
application_fee_percent: fee,
},
{
stripeAccount: accountId,
}
);
Subscription created successfully based on product and price.but i can't wait for 1 month (next billing) for testing so i need to test now how will work for next payment.it will auto deduct from payment method? or customer will notify about next due and have to pay? there need more code for it?
Stripe has a feature called Test Clocks that allows to move subscriptions forward in time. So you could create a subscription with a test clock, then advance the clock by one month to see exactly what happens.
But to answer your question: if the customer (or the subscription) has a default payment method set, then yes Stripe will automatically attempt to make a payment at the end of every billing cycle.

Stripe discount on upcoming payment of recurring subscription

I have implemented stripe recurring subscription that billed annually. I've proposed an offer for my customers that if they refer our website to 5 of their friends and they register, they will get 50% off on their subscription.
How I'll implement that discount for that particular customer on next payment?
The simplest option would be to apply a Coupon to the customer’s subscription. Then during the next billing cycle of the subscription, the coupon will be automatically applied. That can be done is two steps (here done node.js):
// Create the new Coupon, once
// Doc: https://stripe.com/docs/api/coupons/create
const coupon = await stripe.coupons.create({
percent_off: 50,
duration: 'once', // other possible value are 'forever' or 'repeating'
});
// Then every time a customer match your criteria, update their subscription
// Doc: https://stripe.com/docs/api/subscriptions/update
const subscription = await stripe.subscriptions.update(
'sub_xxx',
{ coupon: coupon.id }
);
Another option would be to apply the coupon to the customer instead of on the subscription directly. In that case the coupon would apply to all recurring charges for that customer.
// Doc: https://stripe.com/docs/api/customers/update
const customer = await stripe.customers.update(
'cus_xxx',
{ coupon: coupon.id }
);

Want to payout money to another bank account using stripe

My requirement is to pay out money directly to the user, users will provide their bank account and money will be directly transferred to their given bank account number.
Bank details will be provided by the user and it's not fixed every time. so I cant manually add a bank account to stripe.
in this context, I am using TokenBankAccountOptions in stripe and written the following code for bank account create.
var options = new TokenCreateOptions
{
BankAccount = new TokenBankAccountOptions
{
Country = "US",
Currency = "usd",
AccountHolderName = "Jenny Rosen",
AccountHolderType = "individual",
RoutingNumber = "110000000",
AccountNumber = "000123456789",
},
};
var service = new TokenService();
Token striptoken = await service.CreateAsync(options);
await Transfer(striptoken.Id);
Now I want to transfer or payout money to a given bank account but the stripe not taking any bank details in payout options or transfer options.
As #sinanspd mentioned, you need to use Stripe Connect for this, and I'd also recommend checking with Support to make sure your use case is supported.

Stripe ignoring billing_cycle_anchor when creating a new subscription and an invoice is created straight away. Why is this happening?

I am using Stripe in NodeJS to create subscirptions. I want an invoice to be generated near the end of the billing period. For example, if the billing period is 1-30 Septmeber, I want the invoice to be generated on 30 September. The API docs says that billing_cycle_anchor should do this. But it has no effect when I use it, as an invoice is generated straight away and the user is charged. Code example below.
stripeSubscription = await stripe.subscriptions.create({
customer: id,
items: [{ plan: planId }],
billing_cycle_anchor: moment()
.add('30', 'days')
.unix();,
});
How can I get monthly subscription to generate and charge at the end of the billing period?
Can billing_cycle_anchor be set to the 1st of January, regardless of when the user starts the subscription?
e.g.
this.currentYear = (new Date()).getFullYear();
this.newYear = (new Date(this.currentYear + 1 + '/01/01 00:01')).getTime()/1000;
Then in the function call:
firebase.default
.firestore()
.collection('users')
.doc(user.uid)
.collection('checkout_sessions')
.add({
price: 'price_BLAHBLAH',
billing_cycle_anchor: this.newYear, //1672503000 01/01/2023 12:10 AM
...
})

Stripe API transfer to Bank Account

Does anyone know how to transfer to a bank account using Stripe API?
In the Stripe Reference it looks very simple: https://stripe.com/docs/api/python#create_transfer
stripe.Transfer.create(
amount=400,
currency="usd",
destination="acct_19MKfXGyOv0GIG6Z",
description="Transfer for test#example.com"
)
I don't understand where the destination id comes from. How can I get the destination id of a bank account?
Thanks
There are two types of transfers with Stripe:
internal transfers, from a Stripe platform account to one of its connected accounts. This is known as a "special-case transfer".
external transfers, from a Stripe account to its associated bank account.
If you only have a single bank account for a given currency, you can use the special value "default_for_currency" for the destination parameter.
E.g. if you run this code:
stripe.Transfer.create(
amount=400,
currency="usd",
destination="default_for_currency",
description="Transfer for test#example.com"
)
then $4.00 would be sent to your USD bank account.
EDIT: On newer API versions (>= 2017-04-06), "internal transfers" are now simply known as "transfers", and "external transfers" are now known as "payouts". Cf. this doc page for more information.
I have to use the below code in my existing project
Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
// Create a Charge:
$charge = \Stripe\Charge::create([
'amount' => 1300,
'currency' => 'GBP',
'customer' => 'cus_FM5OdvqpYD7AbR', // customer id
'transfer_group' => date('y-m-d_h:i:s'),
'transfer_data' => [
'destination' => 'acct_1EuyLUIpWjdwbl8y', // destination id
'amount' => 700
]
]);
dd($charge);
https://stripe.com/docs/connect/custom-accounts
this above link will let you know how to get bank account id
stripe.accounts.create({
country: "US",
type: "custom"
}).then(function(acct) {
// asynchronously called
});
you can get
this code will give acc. id in response that you can use in destination.

Resources