Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update UpdateContactInformationOnStripe.php #254

Closed
wants to merge 1 commit into from
Closed

Update UpdateContactInformationOnStripe.php #254

wants to merge 1 commit into from

Conversation

vincentvankekerix
Copy link
Contributor

@vincentvankekerix vincentvankekerix commented Sep 14, 2018

When Team Billing is being used, the 'stripe_id' database field stays empty for the User Model. When User changes their email address, the listener will not work for changing the email address for the corresponding customer in Stripe, since there is no stripe_id stored in the database. This updated listener will look for the stripe_id at the currentTeam, in order to find the matching customer in Stripe, so that email addresses can be updated.

When Team Billing is being used, the 'stripe_id' database field stays empty for the User Model. When User changes their email address, the listener will not work for changing the email address for the corresponding customer in Stripe, since their is no stripe_id stored in the database. This updated listener will look for the stripe_id at the currentTeam, in order to find the matching customer in Stripe, so that email addresses can be updated.
@taylorotwell
Copy link
Member

Please follow the code formatting standards used by the rest of the library.

@vincentvankekerix
Copy link
Contributor Author

Do you mean following the PSR-2 standard, or do you mean something else?

@rickmacgillis
Copy link
Contributor

I haven't looked into this too much yet, but I've been wondering is using the current team is really the best approach. IIRC Spark allows each TEAM to be billed when using team billing instead of the user. So, updating the current team when a user updates their info might not update the correct team.

@vincentvankekerix
Copy link
Contributor Author

You're very right: besides that, I just realize that when a team member updates their email address (instead of the team owner), the email address of the team member gets pushed to Stripe, which is not the result we want. I'm gonna do some refactoring here!

@rickmacgillis
Copy link
Contributor

@vincentvankekerix - Awesome! I appreciate your work on this alleged issue.

@vincentvankekerix
Copy link
Contributor Author

vincentvankekerix commented Sep 16, 2018

@rickmacgillis You're welcome! Just did some testing, I think the new version below should solve both issues. What do you think?

public function handle($event)
{
    if ($event->user->hasBillingProvider()) {
        $customer = $event->user->asStripeCustomer();

        $customer->email = $event->user->email;

        $customer->save();
    }
    
    foreach ($event->user->ownedTeams as $team) {
        if ($team->hasBillingProvider()) {
            $customer = $team->asStripeCustomer();

            $customer->email = $event->user->email;

            $customer->save();
        }
    }
}

@rickmacgillis
Copy link
Contributor

@vincentvankekerix - It looks more promising. How does it function with unit or feature tests?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants