src/ShopifyApp/Services/BillingPlan.php
public function save()
    {
        if (!$this->response) {
            throw new Exception('No activation response was recieved.');
        }

        // Cancel the last charge
        $planCharge = $this->shop->planCharge();
        if ($planCharge && !$planCharge->isDeclined() && !$planCharge->isCancelled()) {
            $planCharge->cancel();
        }

        // Create a charge
        $charge = Charge::firstOrNew([
            'charge_id' => $this->chargeId,
            'shop_id'   => $this->shop->id,
        ]);

        $charge->plan_id = $this->plan->id;
        $charge->type = $this->plan->type;
        $charge->status = $this->response->status;

        if ($this->plan->isType(Plan::PLAN_RECURRING)) {
            // Recurring plan specifics
            $charge->billing_on = $this->response->billing_on;
            $charge->trial_ends_on = $this->response->trial_ends_on;
        }

        // Set the activated on, try for the API, fallback to today
        $charge->activated_on = $this->response->activated_on ?? Carbon::today()->format('Y-m-d');

        // Merge in the plan details since the fields match the database columns
        $planDetails = $this->chargeParams();
        unset($planDetails['return_url']);
        foreach ($planDetails as $key => $value) {
            $charge->{$key} = $value;
        }

        // Finally, save the charge
        return $charge->save();
    }
public function save()
    {
        if (!$this->response) {
            throw new Exception('No activation response was recieved.');
        }

        // Cancel the last charge
        $planCharge = $this->shop->planCharge();
        if ($planCharge && !$planCharge->isDeclined() && !$planCharge->isCancelled()) {
            $planCharge->cancel();
        }

        // Create a charge
        $charge = Charge::firstOrNew([
            'charge_id' => $this->chargeId,
            'shop_id'   => $this->shop->id,
        ]);

        $charge->plan_id = $this->plan->id;
        $charge->type = $this->plan->type;
        $charge->status = $this->response->status;

        if ($this->plan->isType(Plan::PLAN_RECURRING)) {
            // Recurring plan specifics
            $charge->billing_on = $this->response->billing_on;
            $charge->trial_ends_on = $this->response->trial_ends_on;
        }

        // Set the activated on, try for the API, fallback to today
        $charge->activated_on = $this->response->activated_on ?? Carbon::today()->format('Y-m-d');

        // Merge in the plan details since the fields match the database columns
        $planDetails = $this->chargeParams();
        unset($planDetails['return_url']);
        foreach ($planDetails as $key => $value) {
            $charge->{$key} = $value;
        }

        // Finally, save the charge
        return $charge->save();
    }
Cancels the current charge for the shop, saves the new charge.

@return bool