Stripe testing subscription Lumen 5.1 - stripe-payments

Im running Stripe in test mode.
I've created a Yearly billing plan for 100GBP amount, with a 7 days trial ( directly onto Stripe dashboard. )
However, to test the webhooks i've hardcoded the trial_end:
$trialEnd = new DateTime();
$trialEnd->setTimestamp(time()+120);
$user = Users::find($this->user()['user_id']);
$user->subscription($stripe_plan['stripe_plan'])->trialFor($trialEnd)->create($data['stripeToken'], [
'email' => $this->user()['email']
]);
$user->save();
Basically all goes well, but into stripe dashboard the first invoice for 0 GBP is shown, and after one minute i get the Subscription will end in a minute event. After all, the subscription become Active ( from Trialing ) state.
All the webhooks and even the first subscription add reponse i get the trial ends period instead subscription ends.
How can i get the subscription_ends_at timestamp ?
All webhook requests are having the following timestamps:
{
"id": "evt_18baRrIzJLF7fe6PMDPYD0NM",
"object": "event",
"api_version": "2016-07-06",
"created": 1469558315,
"data": {
"object": {
"id": "sub_8tNBbqy0AmSk8p",
"object": "subscription",
"application_fee_percent": null,
"cancel_at_period_end": false,
"canceled_at": null,
"created": 1469558268,
"current_period_end": 1469558384,
"current_period_start": 1469558268,
"customer": "cus_8tNB1tWYw3Jw7L",
"discount": null,
"ended_at": null,
"livemode": false,
"metadata": {
},
"plan": {
"id": "yearly_200",
"object": "plan",
"amount": 20000,
"created": 1469545724,
"currency": "gbp",
"interval": "year",
"interval_count": 1,
"livemode": false,
"metadata": {
},
"name": "Full Club Membership - Pay Anually",
"statement_descriptor": "FULL MEMBERSHIP",
"trial_period_days": 7
},
"quantity": 1,
"start": 1469558268,
"status": "trialing",
"tax_percent": null,
"trial_end": 1469558384,
"trial_start": 1469558268
}
},
"livemode": false,
"pending_webhooks": 1,
"request": null,
"type": "customer.subscription.trial_will_end"
}
So if you look at trial_start and trial_end is same with current_period_start and current_period_end.
I've though initially that if this is the current period.. fine, but after trial expires the current period shouldn't be trials one.
There is any method to take the subscription_ends_at field from Stripe api ? And also, after the trial period ends, shouldn't send a invoice with the real amount ?
Also, i created a subscription plan with no trial period. That plan after a client subscribed, i get the correct timestamps.
Thanks in advance!

It looks like you figured it out. Basically, the delay comes from the fact that when the timestamp passes for your trial expiration, your request to create a new Invoice on that billing cycle gets added to a queue. Typically the queue will create the new invoice ~immediately, but it can sometimes go several minutes before triggering.
The first Invoice will always have timestamps for the current_period_* that map to the trial_period_* ones. Whereas, the second Invoice (that shows up with the invoice.created-event) will have the accurate timestamps for the billing period.

Oh, now i understand .. i will explain maybe will help someone :D.
Basically if a subscription got a trial period when you subscribe you will get a invoice for 0. Then, even if you set the trial to expire in 2 minutes with the request , the first payment will occur in about 10 minutes :D ( with that payment (if you set a webhook url) you will get a "type": "customer.subscription.updated" event who will contain all desired informations. At that time you can update your subscription_ends_at .
I didn't wait 10 minutes to see if the new invoice will be triggered.. and created -> removed -> recreated -> removed and so on for 4 hours with different tests.

Related

Why in the Journal Transaction screen is the Post Period value being ignored by the REST API?

I'm trying to use the REST API to create a record in the Journal Transactions screen. The problem I'm running into is that if the Transaction Date I'm using is before the Post Period, I don't want the Post Period to default to the period of the Transaction Date. In the UI, I can force the Post Period to be after the period of the Transaction Date, but it seems in the REST API, it ignores me setting the Post Period and defaults to the Period of the Transaction Date - and if that period is closed, it gives me an error.
Is this a bug that is known, or am I doing something wrong?
Here's a snippet of my JSON string - not sure that this matters, just wanted to show I was actually setting the Post Period field AFTER setting the transaction date....
{
"Module": {
"value": "GL"
},
"TransactionDate": {
"value": "10/31/2022 11:00:00 PM"
},
"PostPeriod": {
"value": "012023"
},
"Ledger": {
"value": "ACTUAL"
},
"Description": {
"value": "ID: 7731"
},
"ControlTotal": {
"value": "5842.32"
}
}
Thanks...

Stripe: Get all the transactions involved in a payout paid event webhook

I am subscribing to the payout.paid event of stripe.
The payout object has the following object:
{
"id": "po_1H50scIkcSPJwVI7bFSQmBnV",
"object": "payout",
"amount": 1100,
"arrival_date": 1594782118,
"automatic": true,
"balance_transaction": "txn_1H2z37IkcSPJwVI7rVwkvfCT",
"created": 1594782118,
"currency": "usd",
"description": "STRIPE PAYOUT",
"destination": "ba_1H50scIkcSPJwVI7MshqFr6u",
"failure_balance_transaction": null,
"failure_code": null,
"failure_message": null,
"livemode": false,
"metadata": {},
"method": "standard",
"source_type": "card",
"statement_descriptor": null,
"status": "in_transit",
"type": "bank_account"
}
Ref: https://stripe.com/docs/api/payouts/object
I am able to get this event in my webhook but I am interested in getting the transactions "involved" in this Payout.
Let's say if the payout is of $100 and I have two products of $2 and $5 each, I need to determine how many of those transactions are there from each price.
Not able to find it in docs but from the UI we can do this by going to the individual payout from the payouts screen from the "export" button beside the transactions section header:
You'd use the "List all Balance Transactions" endpoint and specify the Payout ID there: https://stripe.com/docs/api/balance_transactions/list#balance_transaction_list-payout
That way you receive a list of all balance transactions that were a part of that specific Payout.

Does Stripe instant payout allow for an instant charge to payout?

I've been attempting to use Stripe Instant Payout to go from charge to a payout in "mere moments" as documented here : https://stripe.com/docs/connect/payouts#instant-payouts
This has proved to be confusing and difficult.
I currently have a Stripe account with a "Connect"ed Stripe profile. I create the charge for the Connect user, (which has an instant pay valid card) and then I create the payout. When I go to payout, using the method here, it fails, saying the balance isn't available.
Why is this? The balance is in pending, but the docs state "You can pay out an account’s available balance plus its pending balance"
#Newah when you place a charge to a Stripe Connect account that charge is not available for payout immediately. You can check when the charge will be available for payout using the balance transaction object https://stripe.com/docs/api/balance/balance_transaction. You can also get this when retrieving a charge by expanding the balance transaction.
{
"id": "txn_19XJJ02eZvKYlo2ClwuJ1rbA",
"object": "balance_transaction",
"amount": 999,
"available_on": 1483920000,
"created": 1483315442,
"currency": "usd",
"description": null,
"exchange_rate": null,
"fee": 59,
"fee_details": [
{
"amount": 59,
"application": null,
"currency": "usd",
"description": "Stripe processing fees",
"type": "stripe_fee"
}
],
"net": 940,
"source": "ch_19XJJ02eZvKYlo2CHfSUsSpl",
"status": "available",
"type": "charge"
}
The charge will be available for payout on the timestamp set in available_on.

Figure out last completed payment via Accounts.payments: list in AdSense Management API v1.4

I am successfully using Google's AdSense API to retrieve payments. The AdSense account I am testing the app with does not have any completed payments.
I am using Accounts.payments:list to retrieve the payments and currently I am only getting one row with Id = "unpaid". This entry specifies the amount that is available for payment.
My question here is what are the other possible entries in the result? Specifically how can I find last completed payment?
Thank you for your help.
items[] description: "The list of Payments for the account. One or both of a) the account's most recent payment; and b) the account's upcoming payment".
As far I can see id can be "unpaid", or date of the last payment (probably the "payment issued" date):
{
"kind": "adsense#payments",
"items": [
{
"kind": "adsense#payment",
"id": "unpaid",
"paymentAmount": "***.**",
"paymentAmountCurrencyCode": "***"
},
{
"kind": "adsense#payment",
"id": "****-**-**",
"paymentDate": "****-**-**",
"paymentAmount": "***.**",
"paymentAmountCurrencyCode": "***"
}
]
}
how can I find last completed payment?
In my understanding, that is exactly what Accounts.payments:list is (or will be) returning:
your account current balance
last payment (if there was any)

Google Wallet Subscription Free Trial with Initial Payment of 0.00 still Charging

I've set up my JWT to submit a subscription with a free trial, however it still charges the account the recurring fee.
{
"aud": "Google",
"iss": "11481745815237711699",
"request": {
"initialPayment": {
"paymentType": "free_trial",
"price": "0.00",
"currencyCode": "JPY"
},
"name": "Automaton Scheduler Subscription (BASIC)",
"currencyCode": "JPY",
"sellerData": "user_id:9,subscription_id:4",
"recurrence": {
"price": "3000.00",
"frequency": "monthly",
"currencyCode": "JPY"
},
"description": "Monthly subscription with up to 20 users."
},
"exp": 1402563800,
"iat": 1402560200,
"typ": "google/payments/inapp/subscription/v1"
}
Should this not skip the first payment, wait a month, then make a charge?
Am I missing something? Do I have to set the startTime manually? Thanks for any insight!
You do have to manually set the startTime field for the JWT even though it is optional and free_trial is set. It uses a time stamp, so time() + 2600000 will push it back one month. If it's not set, it will charge when the order is made.
https://developers.google.com/wallet/digital/docs/jsreference#jwt

Resources