Skip to content

Commit

Permalink
Merge pull request #68 from afterpay/EIT-3456
Browse files Browse the repository at this point in the history
EIT-3456 Update the Create Checkout Response to append iQ Pixel device ID (if available)
  • Loading branch information
chesterz-afterpay authored Dec 18, 2023
2 parents aec0eb5 + 1bf7f91 commit 5a3060c
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/HTTP/Response/CreateCheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,41 @@ public function __construct()
{
parent::__construct();
}

/**
* This method is called immediately after the HTTP response is received.
*
* Updates the redirectCheckoutUrl to include the deviceId from iQ Pixel.
*
* WARNING: This method manipulates the raw HTTP response!
*
* @return \Afterpay\SDK\HTTP\Response\CreateCheckout
*/
public function afterReceive()
{
if ($this->isSuccessful()) {
$bodyObj = $this->getParsedBody();

if (!is_null($bodyObj)) {
// Append iQ Pixel device ID
$cookieName = "apt_pixel";

if (isset($_COOKIE[$cookieName])) {
$decodedCookie = base64_decode($_COOKIE[$cookieName], true);

if ($decodedCookie) {
$cookieObj = json_decode($decodedCookie, false);

if (isset($cookieObj->deviceId)) {
$bodyObj->redirectCheckoutUrl .= "&deviceId={$cookieObj->deviceId}";

$this->setRawBody(json_encode($bodyObj, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
}
}
}
}
}

return $this;
}
}

0 comments on commit 5a3060c

Please sign in to comment.