Jump to content

Stripe Webook - Update our stored card expiry and last4 when Stripe notifies


twikamltd

Recommended Posts

Hi Guys,

 

Have written a file for Stripe to fire customer.source.updated webhooks at, and update the card expiry and last 4 if changed. However it doesn't actually update WHMCS at all. Wonder if anyone can help?

 

<?php

// Init WHMCS
require('/home/xxxxx/public_html/init.php');

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

//$event_json->data->object->exp_month
//$event_json->data->object->exp_year
//$event_json->data->object->last4
//$event_json->data->object->customer

// Which customer is this

if(substr($event_json->data->object->customer,0,3) == 'cus'){

 // Find customer ID for API call later
 $result = select_query( 'tblclients', 'id', array( 'gatewayid' => $event_json->data->object->customer ) );
 $data = mysql_fetch_array( $result );
 $customer_id = $data['id'];

 // Format the card details to the what WHMCS API wants as per https://developers.whmcs.com/api-reference/updateclient/
 $new_exp_month = sprintf("%02d", $event_json->data->object->exp_month);
 $new_exp_year = $event_json->data->object->exp_year;
 $new_last4 = $event_json->data->object->last4;
 $cardExpiry = $new_exp_month.substr($new_exp_year, -2);

 // Update WHMCS with new card expiry details, use ***** to pad out card number
 $command = 'UpdateClient';
 $postData = array(
     'action' => 'UpdateClient',
     'clientid' => $customer_id,
     'expdate' => $cardExpiry
     'cardnum' => '************'.$new_last4
 );
 $adminUsername = 'xx';
 $results = localAPI($command, $postData, $adminUsername);
}

http_response_code(200);
echo "Done:<br /><br />";print_r($results);
echo "<br /><br />\$new_exp_month = ".$new_exp_month;
echo "<br /><br />Local API call data: <br />";
print_r($postData);
?>

 

 

Tried just limiting it to the expiry date, same thing, API call returns success but doesn't update anything.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated