B
B
BonBon Slick2017-03-04 16:46:14
Stripes
BonBon Slick, 2017-03-04 16:46:14

Cashier ERROR: Method newSubscription() does not exist?

Here is my model:

namespace App\Entities;

use Illuminate\Database\Eloquent\Model;
use Prettus\Repository\Contracts\Transformable;
use Prettus\Repository\Traits\TransformableTrait;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravel\Cashier\Billable;
use Illuminate\Database\Eloquent\SoftDeletes;

class User extends Model implements Transformable
{

    use TransformableTrait, Notifiable, Billable, SoftDeletes;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
    'name',
    'email',
    'password',
    'account_type',
    'stripe_id',
    'card_brand',
    'card_last_four',
    'trial_ends_at',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
    'remember_token',
    ];
    protected $dates = [
    'trial_ends_at',
    'ends_at',
    ];
}

When registering, it passes validation, and I try to create a subscription. A subscription to stripe has been created.
Registration controller:
namespace App\Http\Controllers\Auth;

use App\Entities\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;

class RegisterController extends Controller
....

protected function create(array $data)
    {
        $stripeToken = $data['stripeToken'];
        $accountType = strtolower($data['account_type']);
        $user = User::create([
            'account_type' => $accountType,
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
            ]);
        $subscriber = User::where('email', $data['email'])->get();
        if($accountType == 'individual')
        {
             $subscriber->newSubscription('individual', 'individual')->create($stripeToken);
 // тут выкидывает ошибку
        }
        else
        {
            return 'NOT individual!!!';
        }
        return 'DONE!';
    }

Stripe in test mode, the token comes after submitting the form.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
BonBon Slick, 2017-03-05
@BonBonSlick

The question can be deleted, I looked at the function in the line:

$subscriber = User::where('email', $data['email'])->get();
//а надо 
$subscriber = User::where('email', $data['email'])->first();

A
Alexander Pushkarev, 2017-03-04
@AXP-dev

Everything is described in the error itself. You don't have newSubscription() method and you are trying to call it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question