Stripe webhook test

type == “invoice.payment_succeeded”) {
// Verify that this event is from Stripe
\Stripe\Stripe::setApiKey(“sk_test_UPerPnlhN9nqhJgEJxafYjFp”);

// Verify the event by fetching it from Stripe
$event = \Stripe\Event::retrieve($event_json->id);

if ($event) {
// Event is invoice.payment_succeeded
// Extract information
//log_to_wp(json_encode($event_json->data->object->lines, JSON_PRETTY_PRINT));

// Create a transaction
$userId = $event_json->data->object->lines->data[0]->metadata->userId;
$email = $event_json->data->object->lines->data[0]->metadata->email;
$transactionId = $event_json->data->object->id; // Use the invoice id
$productCode = $event_json->data->object->lines->data[0]->metadata->productCode;
$amount = floatval($event_json->data->object->total)/100.00;
$currency = strtoupper($event_json->data->object->currency);
$date = date(“Y-m-d\TH:i:s.000\Z”,$event_json->data->object->date);

$postFields = ‘{“userId”:”‘. $userId . ‘”,”email”:”‘ . $email . ‘”,”transactionId”:”‘ . $transactionId . ‘”,”productCode”:”‘ . $productCode . ‘”,”amount”:’ . $amount . ‘,”currency”:”‘ . $currency . ‘”,”testDate”:{“__type”:”Date”,”iso”:”‘ . $date . ‘”},”type”:”purchase”}’;
log_to_wp($postFields);
$rest = curl_init();
curl_setopt($rest, CURLOPT_URL, ‘https://parseapi.back4app.com/functions/createPurchaseTransaction’);
curl_setopt($rest, CURLOPT_HTTPHEADER, array(
‘X-Parse-Application-Id: 9s7Zfx1VQafAc1raQ9iHvWpNIfYk7nGV8YX8h5jq’,
‘X-Parse-Master-Key: OteMK5EzwL4nl2gm1uR3qVXXxL54yL3PSsBDzCUl’,
‘Content-Type: application/json’
));
curl_setopt($rest, CURLOPT_POST, 1);
curl_setopt($rest, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($rest, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($rest);
curl_close($rest);
$output = json_decode($output, 1);

log_to_wp(json_encode($output, JSON_PRETTY_PRINT));
}

}

http_response_code(200); // PHP 5.4 or greater

?>

Download Now For FREE

SwingProfile golf swing analyzer and training aid is a must-have for golfers of all level.

Download on the App Store