Skip to content

Commit

Permalink
Merge pull request #40 from RF1705/master
Browse files Browse the repository at this point in the history
add Refund to ShopServerGateway
  • Loading branch information
judgej authored Aug 23, 2022
2 parents db99eb6 + 49ae95b commit 70552f7
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 8 deletions.
9 changes: 9 additions & 0 deletions src/AbstractShopGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,13 @@ public function getWalletType()
{
return $this->getParameter('wallettype');
}
public function getMandateId()
{
return $this->getParameter('mandateId');
}

public function setMandateId($id)
{
return $this->setParameter('mandateId', $id);
}
}
4 changes: 2 additions & 2 deletions src/Message/ShopServerAuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ShopServerAuthorizeRequest extends AbstractRequest
*/
protected function getBaseData()
{
$data = array(
$data = [
'mid' => $this->getMerchantId(),
'portalid' => $this->getPortalId(),
// Only md5 is used to encode the key for the Server API (no hashing is
Expand All @@ -47,7 +47,7 @@ protected function getBaseData()
'request' => $this->request_code,
'encoding' => $this->getEncoding(),
'language' => $this->getLanguage(),
);
];

return $data;
}
Expand Down
20 changes: 20 additions & 0 deletions src/Message/ShopServerManageMandateRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Omnipay\Payone\Message;

/**
* PAYONE Shop Authorize Request
*/

class ShopServerManageMandateRequest extends ShopServerAuthorizeRequest
{
/**
* The "request" parameter.
*/
protected $request_code = 'managemandate';

protected function createResponse($data)
{
return $this->response = new ShopServerManageMandateResponse($this, $data);
}
}
11 changes: 11 additions & 0 deletions src/Message/ShopServerManageMandateResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Omnipay\Payone\Message;

/**
* Shop Payment Response
*/

class ShopServerManageMandateResponse extends ShopServerAuthorizeResponse
{
}
157 changes: 157 additions & 0 deletions src/Message/ShopServerRefundRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<?php

namespace Omnipay\Payone\Message;

/**
* PAYONE Shop Capture Request
*/

use Omnipay\Common\Exception\InvalidRequestException;

class ShopServerRefundRequest extends ShopServerAuthorizeRequest
{
/**
* Values for the settleAccount parameter.
*/
const SETTLE_ACCOUNT_YES = 'yes';
const SETTLE_ACCOUNT_NO = 'no';
const SETTLE_ACCOUNT_AUTO = 'auto';

/**
* Values for the invoiceDeliveryMode parameter.
*/
const INVOICE_DELIVERY_MODE_POST = 'M'; // aka Mail
const INVOICE_DELIVERY_MODE_PDF = 'P'; // via email
const INVOICE_DELIVERY_MODE_NONE = 'N'; // no delivery

/**
* The "request" parameter.
*/
protected $request_code = 'refund';

/**
* Collect the data together to send to the Gateway.
*/
public function getData()
{
$data = $this->getBaseData();

$data['txid'] = $this->getTransactionReference();

$sequence_number = $this->getSequenceNumber();
if (isset($sequence_number)) {
$data['sequencenumber'] = $sequence_number;
}

// Amount is in minor units.
$data['amount'] = $this->getAmountInteger() * -1;

// Currency is (i.e. has to be) ISO 4217
$data['currency'] = $this->getCurrency();

$data['transactiontype'] = 'RT';

if ($this->getDescription()) {
$data['narrative_text'] = substr($this->getDescription(), 0, 80);
}

if ($this->getSettleAccount()) {
$data['settleaccount'] = $this->getSettleAccount();
}

if ($this->getDataItems()) {
$data = array_merge($data, $this->getDataItems());
}

if ($this->getMerchantInvoiceId()) {
$data['invoiceid'] = $this->getMerchantInvoiceId();
}

if ($this->getInvoiceDeliveryMode()) {
$data['invoice_deliverymode'] = $this->getInvoiceDeliveryMode();
}

if ($this->getInvoiceDeliveryDate()) {
$data['invoice_deliverydate'] = $this->getInvoiceDeliveryDate();
}

if ($this->getInvoiceDeliveryEndDate()) {
$data['invoice_deliveryenddate'] = $this->getInvoiceDeliveryEndDate();
}

if ($this->getInvoiceAppendix()) {
$data['invoiceappendix'] = $this->getInvoiceAppendix();
}

if ($this->getMandateId()) {
$data['mandate_identification'] = $this->getMandateId();
}

return $data;
}

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

/**
* The sequence number is used to capture the total in smaller amounts.
*/
public function setSequenceNumber($sequenceNumber)
{
if (!is_numeric($sequenceNumber)) {
throw new InvalidRequestException('Sequence Number must be numeric.');
}

return $this->setParameter('sequenceNumber', $sequenceNumber);
}

public function getSequenceNumber()
{
return $this->getParameter('sequenceNumber');
}

/**
* The PAYONE gateway identifier.
*/
public function getTransactionReference()
{
return $this->getParameter('txid');
}


/**
* Sets whether you want to settle the account or not.
*/
public function setSettleAccount($settleAccount)
{
// Allow tre/false/null for convenience.
if ($settleAccount === true) {
$settleAccount = static::SETTLE_ACCOUNT_YES;
} elseif ($settleAccount === false) {
$settleAccount = static::SETTLE_ACCOUNT_NO;
} elseif (!isset($settleAccount)) {
$settleAccount = static::SETTLE_ACCOUNT_AUTO;
}

if ($settleAccount != static::SETTLE_ACCOUNT_YES
&& $settleAccount != static::SETTLE_ACCOUNT_NO
&& $settleAccount != static::SETTLE_ACCOUNT_AUTO
) {
throw new InvalidRequestException('Invalid value for settleAccount.');
}

return $this->setParameter('settleAccount', $settleAccount);
}

public function getSettleAccount()
{
return $this->getParameter('settleAccount');
}

public function setTxid($txid)
{
return $this->setParameter('txid', $txid);
}
}
11 changes: 11 additions & 0 deletions src/Message/ShopServerRefundResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Omnipay\Payone\Message;

/**
* Shop Payment Response
*/

class ShopServerRefundResponse extends ShopServerAuthorizeResponse
{
}
13 changes: 9 additions & 4 deletions src/ShopClientGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* driver for Omnipay
*/

use Omnipay\Common\Exception\InvalidRequestException;

class ShopClientGateway extends AbstractShopGateway
{
/**
Expand All @@ -20,7 +18,6 @@ class ShopClientGateway extends AbstractShopGateway
protected $javascript_url = 'https://secure.pay1.de/client-api/js/v1/payone_hosted_min.js';
protected $endpoint = 'https://secure.pay1.de/client-api/';


public function getName()
{
return 'PAYONE Shop Client';
Expand All @@ -35,7 +32,7 @@ public function getDefaultParameters()

$params['responseType'] = array(
static::RETURN_TYPE_JSON,
static::RETURN_TYPE_REDIRECT,
static::RETURN_TYPE_REDIRECT
);

return $params;
Expand Down Expand Up @@ -96,6 +93,14 @@ public function creditCardCheck(array $parameters = array())
return $this->createRequest(Message\ShopClientCardCheckRequest::class, $parameters);
}

/**
* Helper for generating the hidden fields in a credit card tokenisation AJAX form.
*/
public function managemandate(array $parameters = array())
{
return $this->createRequest(Message\ShopServerManageMandateRequest::class, $parameters);
}

/**
* Accept an incoming notification (a ServerRequest).
* This API supports the notification responses as well as the complete* responses.
Expand Down
18 changes: 16 additions & 2 deletions src/ShopServerGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* ONEPAY Shop (single payments) driver for Omnipay
*/

use Omnipay\Common\Exception\InvalidRequestException;

class ShopServerGateway extends AbstractShopGateway
{
public function getName()
Expand Down Expand Up @@ -39,6 +37,14 @@ public function capture(array $parameters = array())
return $this->createRequest(Message\ShopServerCaptureRequest::class, $parameters);
}

/**
* For handling a capture action.
*/
public function refund(array $parameters = array())
{
return $this->createRequest(Message\ShopServerRefundRequest::class, $parameters);
}

/**
* Check a credit card detail for "plausability" and get a card token in response.
* This would normally be done client-side, but is available server side too for
Expand All @@ -49,6 +55,14 @@ public function creditCardCheck(array $parameters = array())
return $this->createRequest(Message\ShopServerCardCheckRequest::class, $parameters);
}

/**
* Helper for managing Sepa Direct Debit Mandate
*/
public function managemandate(array $parameters = array())
{
return $this->createRequest(Message\ShopServerManageMandateRequest::class, $parameters);
}

/**
* For handling a void action.
*/
Expand Down

0 comments on commit 70552f7

Please sign in to comment.