Skip to content

Minor update #1

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
6 changes: 6 additions & 0 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Omnipay\Common\AbstractGateway;
use Omnipay\Worldline\Message\CompletePurchaseRequest;
use Omnipay\Worldline\Message\PurchaseRequest;
use Omnipay\Worldline\Message\RefundRequest;

/**
* Worldline Hosted Checkout Gateway
Expand Down Expand Up @@ -69,4 +70,9 @@ public function completePurchase(array $parameters = [])
{
return $this->createRequest(CompletePurchaseRequest::class, $parameters);
}

public function refund(array $parameters = [])
{
return $this->createRequest(RefundRequest::class, $parameters);
}
}
2 changes: 2 additions & 0 deletions src/Message/CompletePurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public function setHostedCheckoutId($value)

public function getData()
{
$this->validate('merchantId', 'hostedCheckoutId');

return $this->httpRequest->request->all();
}

Expand Down
18 changes: 17 additions & 1 deletion src/Message/PurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,22 @@ public function setSessionTimeout($value)
return $this->setParameter('sessionTimeout', $value);
}

public function getTransactionChannel()
{
return $this->getParameter('transactionChannel');
}

/**
* Transaction channel can only be either 'ECOMMERCE' or 'MOTO'
*/
public function setTransactionChannel($value)
{
if (!in_array($value, ['ECOMMERCE', 'MOTO'])) {
$value = null;
}
return $this->setParameter('transactionChannel', $value);
}

public function getData()
{
$this->validate('merchantId', 'amount', 'currency');
Expand All @@ -141,7 +157,7 @@ public function getData()
$data = [
'cardPaymentMethodSpecificInput' => [
'authorizationMode' => 'SALE',
'transactionChannel' => 'ECOMMERCE',
'transactionChannel' => $this->getTransactionChannel() ?? 'ECOMMERCE',
],
'hostedCheckoutSpecificInput' => [
// if adding locale, validate locale against known formats
Expand Down
50 changes: 50 additions & 0 deletions src/Message/RefundRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Omnipay\Worldline\Message;

/**
* Worldline Refund Request
*
* @see https://docs.direct.worldline-solutions.com/en/api-reference#tag/Payments/operation/RefundPaymentApi
*/
class RefundRequest extends PurchaseRequest
{
protected $requestMethod = 'POST';

public function getPaymentId()
{
return $this->getParameter('paymentId');
}

public function setPaymentId($value)
{
return $this->setParameter('paymentId', $value);
}

public function getData()
{
$this->validate('merchantId', 'amount', 'currency', 'paymentId');

$data = [
'amountOfMoney' => [
'amount' => $this->getAmountInteger(),
'currencyCode' => $this->getCurrency(),
],
'operationReferences' => [
'merchantReference' => $this->getTransactionId(),
],
];

return $data;
}

protected function createResponse($data)
{
return $this->response = new RefundResponse($this, json_decode($data));
}

protected function getAction()
{
return '/v2/'.$this->getMerchantId().'/payments/'.$this->getPaymentId();
}
}
51 changes: 51 additions & 0 deletions src/Message/RefundResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Omnipay\Worldline\Message;

use Omnipay\Common\Message\AbstractResponse;

/**
* Worldline Refund Response
*/
class RefundResponse extends AbstractResponse
{
/**
* Is the response successful?
*
* @return boolean
*/
public function isSuccessful()
{
return !isset($this->data->errorId) && $this->data->status == 'REFUNDED';
}

/**
* Numeric status code (also in back office / report files)
*
* @return null|string
*/
public function getCode()
{
return $this->data->statusOutput->statusCode ?? $this->data->refundResult->statusOutput->statusCode ?? null;
}

/**
* Get the authorisation code if available.
*
* @return null|string
*/
public function getTransactionReference()
{
return $this->data->id ?? null;
}

/**
* Get the merchant response message if available.
*
* @return null|string
*/
public function getMessage()
{
return $this->data->status ?? $this->data->errorId ?? null;
}
}
2 changes: 1 addition & 1 deletion tests/GatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function testCompletePurchaseFailure()

$options = array_merge($this->options, ['hostedCheckoutId' => '0000000001']);

$response = $this->gateway->completePurchase($this->options)->send();
$response = $this->gateway->completePurchase($options)->send();

$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
Expand Down