@@ -160,7 +160,8 @@ protected function createPrice($amount, $currencyCode)
160160 */
161161 public function getCheckoutSession ($ storeId , $ checkoutSessionId )
162162 {
163- $ response = $ this ->clientFactory ->create ($ storeId )->getCheckoutSession ($ checkoutSessionId );
163+ $ headers = $ this ->getPlatformHeaders ();
164+ $ response = $ this ->clientFactory ->create ($ storeId )->getCheckoutSession ($ checkoutSessionId , $ headers );
164165
165166 return $ this ->processResponse ($ response , __FUNCTION__ );
166167 }
@@ -201,7 +202,8 @@ public function updateCheckoutSession($quote, $checkoutSessionId, $paymentIntent
201202 'platformId ' => $ this ->amazonConfig ->getPlatformId (),
202203 ];
203204
204- $ response = $ this ->clientFactory ->create ($ storeId )->updateCheckoutSession ($ checkoutSessionId , $ payload );
205+ $ headers = $ this ->getPlatformHeaders ();
206+ $ response = $ this ->clientFactory ->create ($ storeId )->updateCheckoutSession ($ checkoutSessionId , $ payload , $ headers );
205207
206208 return $ this ->processResponse ($ response , __FUNCTION__ );
207209 }
@@ -215,7 +217,8 @@ public function updateCheckoutSession($quote, $checkoutSessionId, $paymentIntent
215217 */
216218 public function getCharge ($ storeId , $ chargeId )
217219 {
218- $ response = $ this ->clientFactory ->create ($ storeId )->getCharge ($ chargeId );
220+ $ headers = $ this ->getPlatformHeaders ();
221+ $ response = $ this ->clientFactory ->create ($ storeId )->getCharge ($ chargeId , $ headers );
219222 return $ this ->processResponse ($ response , __FUNCTION__ );
220223 }
221224
@@ -232,7 +235,7 @@ public function getCharge($storeId, $chargeId)
232235 */
233236 public function createCharge ($ storeId , $ chargePermId , $ amt , $ currency , $ captureNow = false , $ merchantRefId = null )
234237 {
235- $ headers = $ this ->getIdempotencyHeader ();
238+ $ headers = array_merge ( $ this ->getIdempotencyHeader (), $ this -> getPlatformHeaders () );
236239
237240 $ payload = [
238241 'chargePermissionId ' => $ chargePermId ,
@@ -261,7 +264,7 @@ public function createCharge($storeId, $chargePermId, $amt, $currency, $captureN
261264 */
262265 public function captureCharge ($ storeId , $ chargeId , $ amount , $ currency , $ headers = [])
263266 {
264- $ headers = array_merge ($ headers , $ this ->getIdempotencyHeader ());
267+ $ headers = array_merge ($ headers , $ this ->getIdempotencyHeader (), $ this -> getPlatformHeaders () );
265268
266269 $ payload = [
267270 'captureAmount ' => $ this ->createPrice ($ amount , $ currency ),
@@ -283,7 +286,7 @@ public function captureCharge($storeId, $chargeId, $amount, $currency, $headers
283286 */
284287 public function createRefund ($ storeId , $ chargeId , $ amount , $ currency )
285288 {
286- $ headers = $ this ->getIdempotencyHeader ();
289+ $ headers = array_merge ( $ this ->getIdempotencyHeader (), $ this -> getPlatformHeaders () );
287290
288291 $ payload = [
289292 'chargeId ' => $ chargeId ,
@@ -304,7 +307,8 @@ public function createRefund($storeId, $chargeId, $amount, $currency)
304307 */
305308 public function getRefund ($ storeId , $ refundId )
306309 {
307- $ response = $ this ->clientFactory ->create ($ storeId )->getRefund ($ refundId );
310+ $ headers = $ this ->getPlatformHeaders ();
311+ $ response = $ this ->clientFactory ->create ($ storeId )->getRefund ($ refundId , $ headers );
308312 return $ this ->processResponse ($ response , __FUNCTION__ );
309313 }
310314
@@ -317,7 +321,8 @@ public function getRefund($storeId, $refundId)
317321 */
318322 public function getChargePermission (int $ storeId , string $ chargePermissionId )
319323 {
320- $ response = $ this ->clientFactory ->create ($ storeId )->getChargePermission ($ chargePermissionId );
324+ $ headers = $ this ->getPlatformHeaders ();
325+ $ response = $ this ->clientFactory ->create ($ storeId )->getChargePermission ($ chargePermissionId , $ headers );
321326
322327 return $ this ->processResponse ($ response , __FUNCTION__ );
323328 }
@@ -355,7 +360,8 @@ public function updateChargePermission(int $storeId, string $chargePermissionId,
355360 $ payload ['recurringMetadata ' ] = $ data ['recurringMetadata ' ];
356361 }
357362
358- $ response = $ this ->clientFactory ->create ($ storeId )->updateChargePermission ($ chargePermissionId , $ payload );
363+ $ headers = $ this ->getPlatformHeaders ();
364+ $ response = $ this ->clientFactory ->create ($ storeId )->updateChargePermission ($ chargePermissionId , $ payload , $ headers );
359365
360366 return $ this ->processResponse ($ response , __FUNCTION__ );
361367 }
@@ -373,7 +379,8 @@ public function cancelCharge($storeId, $chargeId, $reason = 'ADMIN VOID')
373379 'cancellationReason ' => $ reason
374380 ];
375381
376- $ response = $ this ->clientFactory ->create ($ storeId )->cancelCharge ($ chargeId , $ payload );
382+ $ headers = $ this ->getPlatformHeaders ();
383+ $ response = $ this ->clientFactory ->create ($ storeId )->cancelCharge ($ chargeId , $ payload , $ headers );
377384
378385 return $ this ->processResponse ($ response , __FUNCTION__ );
379386 }
@@ -394,7 +401,8 @@ public function closeChargePermission($storeId, $chargePermissionId, $reason, $c
394401 'cancelPendingCharges ' => $ cancelPendingCharges ,
395402 ];
396403
397- $ response = $ this ->clientFactory ->create ($ storeId )->closeChargePermission ($ chargePermissionId , $ payload );
404+ $ headers = $ this ->getPlatformHeaders ();
405+ $ response = $ this ->clientFactory ->create ($ storeId )->closeChargePermission ($ chargePermissionId , $ payload , $ headers );
398406
399407 return $ this ->processResponse ($ response , __FUNCTION__ );
400408 }
@@ -452,9 +460,11 @@ public function completeCheckoutSession($storeId, $sessionId, $amount, $currency
452460 'chargeAmount ' => $ this ->createPrice ($ amount , $ currencyCode ),
453461 ];
454462
463+ $ headers = $ this ->getPlatformHeaders ();
455464 $ rawResponse = $ this ->clientFactory ->create ($ storeId )->completeCheckoutSession (
456465 $ sessionId ,
457- json_encode ($ payload )
466+ json_encode ($ payload ),
467+ $ headers
458468 );
459469 return $ this ->processResponse ($ rawResponse , __FUNCTION__ );
460470 }
@@ -549,6 +559,20 @@ protected function getIdempotencyHeader()
549559 ];
550560 }
551561
562+ /**
563+ * Create headers for platform and integration/module version
564+ *
565+ * @return array
566+ */
567+ protected function getPlatformHeaders ()
568+ {
569+ return [
570+ 'x-amz-pay-platform-version ' => $ this ->productMetadata ->getVersion (),
571+ 'x-amz-pay-integrator-version ' => $ this ->amazonHelper ->getModuleVersion ('Amazon_Pay ' ),
572+ 'x-amz-pay-integrator-id ' => $ this ->amazonConfig ->getPlatformId ()
573+ ];
574+ }
575+
552576 /**
553577 * Generate login static signature for amazon.Pay.renderButton used by checkout.js
554578 *
0 commit comments