简体   繁体   中英

How can I read Cookie through Webhook in PHP?

I'm using selz.com to process payments and I can use test webhooks to my files.

For example, I have whtest.php .

if(isset($_COOKIE['Affiliate']))
{
    $aff_code = $_COOKIE['Affiliate'];
}
file_put_contents('webhook_data.txt', $aff_code, FILE_APPEND);  

//WEBHOOK
$json = json_decode(file_get_contents('php://input'), TRUE);
file_put_contents('webhook_data.txt', $json, FILE_APPEND);

The cookie is already there. So if I go to whtest.php and access it directly from the browser it will write the cookie data inside webhook_data.txt . That's all fine.

The problem is that if I send test some random webhook data to whtest.php it gets it successfuly into webhook_data.txt but not the data from the cookie too. How can I solve this?

The short answer is you can't use a cookie in this circumstance. The webhook will have no knowledge of a cookie that you set for your user on your site.

I'm not familiar with selz (so sorry I can't be more specific), but you'll have to find some piece of data that is sent in the webhook that you also have access to prior to your user making the purchase. Something like a shopping cart id, transaction id, order id, session token, etc. Any identifier that is unique to that user's purchase.

Once you have that data, you will need to make a call to your server prior to the purchase happening, and persist in a database the relationship of this id -> affiliate_sale. Once the webhook call is made, you then use that piece of data sent by selz to do a lookup for its match in your database. You can then do whatever you have to do if it was an affiliate sale.

Hope that helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM