3

I am working on a platform offering services. When creating a new subscription, a new transaction for the first billing is created. How can I access the transactions id?

I have a form with Braintree's Drop-in UI and my backend looks currently like this:

if (!auth()->user()->subscribed('main')) {
     $subscription = auth()->user()->newSubscription('main', 'membership-monthly')->create($request->payment_method_nonce, []);
     dd($subscription);
}

This successfully creates a new subscription!

Now I want to access this subscription's first billing transaction's id. enter image description here How can I achieve this?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Codearts
  • 2,816
  • 6
  • 32
  • 54

3 Answers3

1

Probably, you should provide a second parameter to create function, try this:

if (!auth()->user()->subscribed('main')) {
    $payload = array();
    $subscription = auth()
         ->user()
         ->newSubscription('main', 'membership-monthly')
         ->create($request->payment_method_nonce, $payload);
    dd($subscription);
    dd($payload);

}
mutas
  • 361
  • 2
  • 8
0

From the Laravel Cashier documentation the database schema looks like this:

Schema::create('subscriptions', function ($table) {
    $table->increments('id');
    $table->unsignedInteger('user_id');
    $table->string('name');
    $table->string('braintree_id');
    $table->string('braintree_plan');
    $table->integer('quantity');
    $table->timestamp('trial_ends_at')->nullable();
    $table->timestamp('ends_at')->nullable();
    $table->timestamps();
});

I would assume to get the subscription in your case would be similar to $subscription->braintree_id

Levi Cole
  • 3,561
  • 1
  • 21
  • 36
-1

If you have an relation between subscription and transactions you need access so :

foreach($subscription->transactions() as $transaction){
   //here you access yo transactions id
   dd($transaction);
}

I hope that i could help you

  • Sadly there isn't a transactions() method. Trying $subscription->transactions returns an empty array as well. – Codearts Sep 26 '18 at 13:10