diff --git a/src/Api/Payment.php b/src/Api/Payment.php index d9b791f..086cc7e 100644 --- a/src/Api/Payment.php +++ b/src/Api/Payment.php @@ -103,7 +103,7 @@ public function cancelPayment($order_id, $text) /** * {@inheritdoc} */ - public function capturePayment($order_id, $text, $amount = 0) + public function capturePayment($order_id, $text, $amount = 0, $request_id = null) { // Build request object from data passed to method. $request = (new RequestCapturePayment()) @@ -120,6 +120,7 @@ public function capturePayment($order_id, $text, $amount = 0) $request->getTransaction()->setAmount($amount); } $resource = new CapturePayment($this->app, $this->getSubscriptionKey(), $order_id, $request); + $resource->setRequestID($request_id); $resource->setPath(str_replace('ecomm', $this->customPath, $resource->getPath())); /** @var \zaporylie\Vipps\Model\Payment\ResponseCapturePayment $response */ $response = $resource->call(); diff --git a/src/Api/PaymentInterface.php b/src/Api/PaymentInterface.php index c53c71e..4db36dd 100644 --- a/src/Api/PaymentInterface.php +++ b/src/Api/PaymentInterface.php @@ -22,10 +22,11 @@ public function cancelPayment($order_id, $text); * @param string $order_id * @param string $text * @param int $amount + * @param string $request_id * * @return \zaporylie\Vipps\Model\Payment\ResponseCapturePayment */ - public function capturePayment($order_id, $text, $amount = 0); + public function capturePayment($order_id, $text, $amount = 0, $request_id = null); /** * @param string $order_id diff --git a/src/Resource/Payment/PaymentResourceBase.php b/src/Resource/Payment/PaymentResourceBase.php index f2ece8d..cf304a1 100644 --- a/src/Resource/Payment/PaymentResourceBase.php +++ b/src/Resource/Payment/PaymentResourceBase.php @@ -32,9 +32,22 @@ public function __construct(\zaporylie\Vipps\VippsInterface $vipps, $subscriptio $this->headers['Content-Type'] = 'application/json'; // By default RequestID is different for each Resource object. - $this->headers['X-Request-Id'] = RequestIdFactory::generate(); + $this->setRequestID(RequestIdFactory::generate()); // Timestamp is equal to current DateTime. $this->headers['X-TimeStamp'] = (new \DateTime())->format(\DateTime::ISO8601); } + + /** + * set specific request ID + * @param string $request_id + * @return $this + */ + public function setRequestID($request_id) + { + if (!empty($request_id)) { + $this->headers['X-Request-Id'] = $request_id; + } + return $this; + } }