laravel cashier with stripe no monthly plan error - laravel

I am having trouble using laravel cashier with stripe new product and plan integration. So i created a product and within that product i created a plan. but when i submit the request to i get an error checked my database the user table contains the card information the subscription table is empty. How do integrate laravel cashier with stripe new system product & plan?
error:
No such plan: Monthly
here my code
public function store(Request $request)
{
$token = $request->stripeToken;
auth()->user()->newSubscription('main', 'Monthly')->create($token);
return 'Done';
}

You need to create a product on stripe(when creating it you can set the billing cycle). Once you have created the product on stripe it will then have a product ID. Instead of using the nickname you have assigned it on stripe you need to use the ID like so
$nickname = 'Monthly';
$plan_id = 'plan_xxxxxxxxxxx';
auth()->user()->newSubscription($nickname, $plan_id)->create($request->stripeToken);

Related

Why is my stripe invoice showing 0 as total?

I am trying to create a one time charge with a pdf invoice with Laravel Cashier for stripe.
The form submit successfuly, however, the invoice total is 0 and there is no payment in the Stripe page of payment list.
I have created one product with multiple price.
I saved the price ids in a table with the product name.
public function purchase(Request $request, SubscriptionPlan $subscriptionPlan)
{
try {
auth()->user()->createOrGetStripeCustomer();
auth()->user()->updateStripeCustomer(['address' => ['country' => 'CA'],'preferred_locales' => ['fr-CA']]);
auth()->user()->updateDefaultPaymentMethod($request->paymentMethod);
auth()->user()->invoicePrice($subscriptionPlan->stripe_price_id, 1); // Product ID from stripe
} catch (\Exception $exception) {
\Log::debug($exception->getMessage());
return back()->with('error', $exception->getMessage());
}
return back()->with('success', 'Paiement effectué avec succès!');
}
Edit:
I found that there are as many "pending invoice items" as $0 invoices.
Pending invoice items
it sound likes a subscription with a trial period, where the first invoice is $0.
Did you specify a trial_period_days or trial_end when creating this subscription? If not, you can reach out to Stripe Support and give them the subscription ID to investigate further.

Using a single payment method ID between multiple customers in Stripe - Laravel Cashier

I have an application with two subscriber levels (company and reader). Person A has already subscribed as a company. He wants to Add person B as a reader subscriber.
Is there a way I can use the same payment method id Person A used in Stripe for the company to subscribe the Person B as a reader? When I try this, I get an error.
The payment method you provided has already been attached to a
customer.
Sample code
$user = User::where('id', 26)->first();
$user->subscription('company')->incrementQuantity(1);
$paymethod = $user->defaultPaymentMethod();
$id = 28;
$user2 = User::where('id', $id)->first();
$user2->newSubscription('reader', 'price_xxx')->create($paymethod->id);
A payment method can only be attached to a single customer. Either the subscription need to belong to the same customer also (and can then use the same payment method), or you'll need to collect the payment method again for a separate customer.

Multiple transaction create in accounts module using a laravel package

I am creating a double entry accounts website in laravel, transaction sale, purchase and cash or bank etc. And i have build the api for an payment website using laravel accounting package eloquent-ifrs , When I create api for add transaction, these trancation is multiple types.
I have all trasaction created expect 'contra entry' transaction because in this transaction main account type not valid for double entry for line item post ledgers.example:-
$contraEntry = ContraEntry::create([
'entity_id' => $entity,
'account_id' => $bankAccount->id,
]);
$zeroVat = DB::table('ifrs_vats')->where('entity_id', $entity)->whereNull('account_id')->first();
$assetAccount = Account::where('account_type', 'BANK')->first();
$contraEntryLineItem = LineItem::create([
'vat_id' => $zeroVat->id,
'account_id' => $assetAccount->id,
'vat_account_id' => $zeroVat->account_id
In this example of code contraEntry transaction created after that lineItem not created. Because A Transaction Main Account cannot be one of the Line Item Accounts.
I have sent parameter account_id for create first ContraEntry::create([]) and required account_type = "BANK" and account_type= "BANK" required in LineItem::create([]) but exist account id can't be send showing this error.
If any one have already worked on this Eloquent IFRS laravel package or working on this "Eloquent IFRS" accounting package.Help me out I really appreciate.

Laravel Cashier list all user invoices

How to display all user invoices for referencing in the admin section of the application.
I can get a user invoices by
$userinvoices = $user->invoices();
Or I can get all invoice by stripe API:
$invoices = \Stripe\Invoice::all(array("limit" => 30));
in the second case, I can't get the details of the user the invoice belongs to.
Or is there any way to save invoice data to database on every creation of the invoice in stripe.
Your first option is the better way to go since you have all the information on the invoice and also the user info on the object.
If you want, you can go to your stripe dashboard -> Your account -> account settings -> webhooks -> add endpoint -> select events and select the invoiceitem.created event. setup your endpoint in the application and do whatever you need with it.
Example:
public function invoiceCreated(Request $request){
$payload = $request->all();
if($payload['type'] == 'invoiceitem.created'){
// do whatever you want with the $payload["data"]...
}
}
Good Luck :)

How to get the payment transaction of a subscription just created through Recurly's Ruby API?

If a subscription is created with
recurly_subscription = Recurly::Subscription.create!( ... )
the corresponding invoice can be retrieved with
recurly_subscription.invoice
But how to retrieve the corresponding payment transaction?
try this:
s = Recurly::Subscription.first
s.invoice.transactions

Resources