| Current Path : /var/www/html/libraries/omnipay3/vendor/omnipay/eway/src/Message/ |
| Current File : /var/www/html/libraries/omnipay3/vendor/omnipay/eway/src/Message/RefundRequest.php |
<?php
/**
* eWAY Rapid Refund Request
*/
namespace Omnipay\Eway\Message;
/**
* eWAY Rapid Refund Request
*
* Refund a transaction processed through eWAY.
* Requires the amount to refund and the eWAY Transaction ID of
* the transaction to refund (passed as transactionReference).
*
* Example -- note this example assumes that the purchase has been successful
* and that the transaction ID returned from the purchase is held in $txn_id.
* See RapidDirectPurchaseRequest for the first part of this example transaction:
*
* <code>
* $transaction = $gateway->refund(array(
* 'amount' => '10.00',
* 'currency' => 'AUD',
* ));
* $transaction->setTransactionReference($txn_id);
* $response = $transaction->send();
* if ($response->isSuccessful()) {
* echo "Refund transaction was successful!\n";
* $data = $response->getData();
* echo "Gateway refund response data == " . print_r($data, true) . "\n";
* }
* </code>
*
* @link https://eway.io/api-v3/#refunds
* @see RapidDirectPurchaseRequest
*/
class RefundRequest extends AbstractRequest
{
public function getData()
{
$this->validate('transactionReference', 'amount');
$data = $this->getBaseData();
$data['Refund']['TotalAmount'] = $this->getAmountInteger();
$data['Refund']['TransactionID'] = $this->getTransactionReference();
$data['Refund']['InvoiceNumber'] = $this->getTransactionId();
$data['Refund']['InvoiceDescription'] = $this->getDescription();
$data['Refund']['CurrencyCode'] = $this->getCurrency();
$data['Refund']['InvoiceReference'] = $this->getInvoiceReference();
if ($this->getItems()) {
$data['Items'] = $this->getItemData();
}
return $data;
}
public function sendData($data)
{
$headers = [
'Authorization' => 'Basic ' . base64_encode($this->getApiKey() . ':' . $this->getPassword())
];
$httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, json_encode($data));
return $this->response = new RefundResponse($this, json_decode((string) $httpResponse->getBody(), true));
}
protected function getEndpoint()
{
return $this->getEndpointBase() . '/DirectRefund.json';
}
}