0

I'm using a Stripe webhook to store the dollar amount a customer is charged when they get charged in Stripe.

I've got the webhook working fine and can email out the charge amount but can't seem to store it in WordPress user_meta field.

Here's what my code looks like:

// Retrieve the request's body and parse it as JSON
$input = @file_get_contents("php://input");
$event_json = json_decode($input);

// Check against Stripe to confirm that the ID is valid
$event = \Stripe\Event::retrieve($event_json->id);

// If charge is successful, store in user meta
if (isset($event) && $event->type == "charge.succeeded") { 
  $amount = $event->data->object->amount / 100;
}
$payment_user_id = 9192321; 
update_user_meta($payment_user_id, 'payment_history', $amount);

Is this because the json received from stripe is in a format that needs to be converted to something before I can store it? If I try to convert it to an integer using intval($amount) it just stores it as 0.

Thanks in advance!

0

Sounds like the $amount variable is empty so it's not saving. Echo it out to see what's happening.

Make sure the $payment_user_id is an actual WordPress user_id.

Wrap your update_user_meta within the if statement.

// If charge is successful, store in user meta
if (isset($event) && $event->type == "charge.succeeded") { 
  $amount = $event->data->object->amount / 100;

  echo $amount . ' <- $amount';

  $payment_user_id = 9192321; 
  update_user_meta($payment_user_id, 'payment_history', $amount);
}
  • 1
    Whelp, I'm dumb. Just need to put it inside of the "if" statement like you suggested. – Christian Oct 26 '16 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.