Laravel \ Касса \ Исключения \ SubscriptionCreationFailed - PullRequest
0 голосов
/ 23 января 2020

как я могу решить эту ошибку или сделать обработку ошибок ??

Laravel \ Cashier \ Exceptions \ SubscriptionCreationFailed с сообщением "Попытка создать подписку на план" ежемесячный usd "для клиента" cus_GbBylIPFPeeM97 "не удалось, так как подписка была неполной. Для получения дополнительной информации о неполных подписках см. https://stripe.com/docs/billing/lifecycle#incomplete"

public function subsrcribeCustomer(Request $request){
    $nok =  env('PLAN_NOK');
    $usd =  env('PLAN_USD');
    $customer = Customer::find(session('id'));
    if($customer->subscribed('main')==false){
        // $response =  $customer
        // ->newSubscription('main', 'plan_FQCahjLGqmbldS')
        // ->create($request->stripeToken, [], ['price' => $request->pkg_price]);
        if($request->currency == "NOK"){
            $unit = 'nok';
            try{
                $response =  $customer
            //    ->newSubscription('main', 'plan_FTu5ehz6fiXbKt')      //live NOK
                ->newSubscription('main', $nok)      //test nok
                ->create($request->stripeToken, [], ['price' => $request->pkg_price]);
            } catch (IncompletePayment $exception) {
                return view('customer-billing.plan_payment_cancel_card');
            }
        }else{
            $unit = 'usd';
            try {
                $response =  $customer
              //  ->newSubscription('main', 'plan_Fg0gT5OZziwo5P')      //live USD
                ->newSubscription('main', $usd)      //test nok
                ->create($request->stripeToken, [], ['price' => $request->pkg_price]);
                }
                 catch (IncompletePayment $exception) {
                 return view('customer-billing.plan_payment_cancel_card');
            }
        }

        CustomerPayments::customerLicenseUpdate(session('id'));

        $braintree_id = $response["stripe_id"];
        $pkg_price    = $request->pkg_price;
        $plan_name    = $request->plan_name;

        CustomerPayments::saveCustomerPayment(session('id'),$pkg_price, $braintree_id, "Subscription of Basic Plan", $unit);
        return view('customer-billing.plan_payment_success', compact('braintree_id','pkg_price','plan_name'));


    }else if($customer->subscribed('main')==true){
        return view('customer-billing.plan_payment_cancel');
    }

}

1 Ответ

0 голосов
/ 23 января 2020

Вот что я сделал. В app / Exceptions / Handler. php это то, что у меня есть и работает.

<?php namespace cablework\Exceptions;

use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Stripe\Error as Stripe;

class Handler extends ExceptionHandler {

    /**
     * A list of the exception types that should not be reported.
     *
     * @var array
     */
    protected $dontReport = [
        'Symfony\Component\HttpKernel\Exception\HttpException'
    ];

    /**
     * Report or log an exception.
     *
     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
     *
     * @param  \Exception  $e
     * @return void
     */
    public function report(Exception $e)
    {
        return parent::report($e);
    }

    /**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Exception  $e
     * @return \Illuminate\Http\Response
     */
    public function render($request, Exception $e)
    {

        if ($e instanceof Stripe\Card)
        {
            session()->flash('error_msg',$e->getMessage() . ' <a class="alert-link" href="'.route('settings.company.creditcard').'">Click here</a> to manage your card.');
            return redirect()->back();
        }

        if ($e instanceof Stripe\RateLimit)
        {
            session()->flash('error_msg','It looks like our payment processor was busy. Please try again in a few minutes.');
            return redirect()->back();
        }

        if ($e instanceof Stripe\Api ||
            $e instanceof Stripe\ApiConnection ||
            $e instanceof Stripe\Authentication ||
            $e instanceof Stripe\InvalidRequest ||
            $e instanceof Stripe\Base)
        {
            session()->flash('error_msg',$e->getMessage());
            return redirect()->back();
        }

        return parent::render($request, $e);
    }

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...