Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic support for request ID in capturePayment #28

Open
wants to merge 2 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Api/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/Api/PaymentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion src/Resource/Payment/PaymentResourceBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}