2

I am having problems with a composer package I am dealing with. It implements a trait Billable.

trait Billable
{
/**
     * Update the payment method token for all of the user's subscriptions.
     *
     * @param  string  $token
     * @return void
     */
    protected function updateSubscriptionsToPaymentMethod($token)
    {
        foreach ($this->subscriptions as $subscription) {
            if ($subscription->active()) {
                BraintreeSubscription::update($subscription->braintree_id, [
                    'paymentMethodToken' => $token,
                ]);
            }
        }
    }
}

I am trying to override this method in my class

class Organisation extends Model
{

    use Billable;

    /**
     * Update the payment method token for all of the user's subscriptions.
     *
     * @param  string  $token
     * @return void
     */
    protected function updateSubscriptionsToPaymentMethod($token)
    {
        foreach ($this->subscriptions as $subscription) {
            if ($subscription->active()) {
                BrntreeSubscription::update($subscription->braintree_id, [
                    'paymentMethodToken' => $token,
                ]);
            }
        }
    }
}

But the method is not overridden. As a test I overrode some of the public functions and they work fine, it this a limitation of traits? I have tried to find the answer online but have come up short.

I am trying to override this function because I need to customize the behaviour of the BraintreeSubscription class.

Any help would be greatly appreciated.

2
  • 3
    You can have a look at stackoverflow.com/questions/11939166/… Commented Sep 11, 2016 at 23:34
  • you should also pass subscriptions as an argument. If you leave it as is it might throw error in somewhere you use trait and you have something other then subscriptions array. Commented Sep 12, 2016 at 4:36

1 Answer 1

3

in your class you could do the following notice the T before the function name you may change this to be aliased as anything really.

use billable {
    updateSubscriptionsToPaymentMethod as tUpdateSubscriptionsToPaymentMethod;
}

then simply in the class add the desired function:

    public function updateSubscriptionsToPaymentMethod(){
      ...
   }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.