Skip to content

Commit

Permalink
Merge pull request #395 from WPUserManager/#9-During-Test-payment-The…
Browse files Browse the repository at this point in the history
…-product-is-not-being-assigned-to-the-user-but-the-payment-is-logged-properly-in-Stripe

Resolved: The product is not being assigned to the user, but the payment is logged properly in Stripe
  • Loading branch information
wp-user-manager authored Mar 11, 2024
2 parents 827445f + 7f18098 commit daf0be9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions includes/integrations/stripe/Billing.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ protected function prepareData( $test_mode, $user, $plan, $returnUrl, $stripe_ac
'plan' => $plan,
'success_url' => $returnUrl,
'cancel_url' => $this->getBillingURL(),
'user_id' => $user->ID,
);

if ( $stripe_account_id ) {
Expand Down
13 changes: 12 additions & 1 deletion includes/integrations/stripe/StripeWebhookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ protected function signatureIsValid( $request ) {
* @throws \Exception
*/
protected function handleCheckoutSessionCompleted( $payload ) {
$subscription = $this->subscriptions->where( 'subscription_id', $payload['data']['object']['subscription'] );
if ( $subscription ) {
return new \WP_REST_Response( 'Webhook handled', 200 );
}

if ( $payload['data']['object']['customer_email'] ) {
$user = get_user_by( 'email', $payload['data']['object']['customer_email'] );
$user_id = $user->ID;
Expand Down Expand Up @@ -160,8 +165,14 @@ protected function handleCustomerSubscriptionCreated( $payload ) {
return new \WP_REST_Response( 'Webhook handled', 200 );
}

$customer_id = $payload['data']['object']['customer'];
// Check if user_id exists in the metadata
if ( isset( $payload['data']['object']['metadata']['user_id'] ) ) {
$user_id = $payload['data']['object']['metadata']['user_id'];

return $this->createSubscription( $user_id, $payload, false );
}

$customer_id = $payload['data']['object']['customer'];
$subscription = $this->subscriptions->where( 'customer_id', $customer_id );
if ( ! $subscription ) {
throw new \Exception( 'Subscription not found' );
Expand Down

0 comments on commit daf0be9

Please sign in to comment.