mercredi 2 août 2017

Braintree swap method fails to update new columns

So I have just started getting familiar with Braintree with Laravel and it seems to be a pretty good package to handle payments and subscriptions. But I have encountered a little problem.

When a user is subscribing, with a "card", and want to change plan and continue with a PayPal solution, the "special" PayPal email seems not to be updated in the users table.

This is my current create method.

public function create(Request $request)
    {
        // Does the plan exist?
        $plan = Plan::findOrFail($request->plan);

        // Check the integrity of the form "value"
        if($request->user()->subscribedToPlan($plan->braintree_plan, 'main')){
            return redirect()->route('account.index')->with('error', 'You already have a subscription to this plan!');
        }

        if(!$request->user()->subscribed('main')) {
            // Add the new subscription record to the database
            $request->user()->newSubscription('main', $plan->braintree_plan)->create($request->payment_method_nonce);
        }else{
            // If user already is subscibed, then swap current plan to another choosen plan
            $request->user()->subscription('main')->swap($plan->braintree_plan);
        }

        // If everything went okey, redirect to account.index with flash message!
        return redirect()->route('account.index')->with('success', 'You have successfully subscribed!');
    }

This issue is also present in the "reverse" order, when I started to sign-up with PayPal, card_brand and card_last_foru is not populated with the new payment method.

How can I populate all "new" columns with the swap method?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire