Skip to content

Commit

Permalink
Iade gelistirmesi gerceklestirildi.
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrahimgunduz34 committed Sep 5, 2015
1 parent d9d6c13 commit f097bc8
Show file tree
Hide file tree
Showing 15 changed files with 452 additions and 44 deletions.
60 changes: 60 additions & 0 deletions src/Payu/Builder/RefundRequestBuilder.php
@@ -0,0 +1,60 @@
<?php
namespace Payu\Builder;

use Payu\Component\Refund;
use Payu\Request\RefundRequest;
use Payu\Serializer\RefundRequestSerializer;
use Payu\Validator\RefundValidator;

class RefundRequestBuilder extends BuilderAbstract
{
/**
* @var \Payu\Component\Refund
*/
protected $refund;

public function setRefund(Refund $refund)
{
$this->refund = $refund;
return $this;
}

public function buildRefund(
$merchant=null,
$orderRef=null,
$orderAmount=null,
$orderCurrency=null,
$irnDate=null,
$amount=null,
$loyaltyPointsAmount=null
) {
$this->refund = new Refund(
$merchant,
$orderRef,
$orderAmount,
$orderCurrency,
$irnDate,
$amount,
$loyaltyPointsAmount
);
return $this;
}

/**
* @return \Payu\Response\ResponseAbstract
*/
public function build()
{
$request = new RefundRequest($this->refund);

$validator = new RefundValidator($request);
$validator->validate();

$serializer = new RefundRequestSerializer($request, $this->configuration);
$rawData = $serializer->serialize();

$request->setRawData($rawData);

return $request;
}
}
22 changes: 22 additions & 0 deletions src/Payu/Client.php
Expand Up @@ -4,12 +4,15 @@
use Guzzle\Http\Exception\RequestException;
use Payu\Builder\LoyaltyInquiryRequestBuilder;
use Payu\Builder\PaymentRequestBuilder;
use Payu\Builder\RefundRequestBuilder;
use Payu\Exception\ConnectionError;
use Payu\Parser\LoyaltyInquiryResponseParser;
use Payu\Parser\PaymentResponseParser;
use Payu\Parser\RefundResponseParser;
use Payu\Parser\ResponseParser;
use Payu\Request\LoyaltyInquiryRequest;
use Payu\Request\PaymentRequest;
use Payu\Request\RefundRequest;
use Payu\Request\RequestAbstract;
use Guzzle\Http\Client as httpClient;

Expand Down Expand Up @@ -45,6 +48,14 @@ public function createLoyaltyInquiryRequestBuilder()
return new LoyaltyInquiryRequestBuilder($this->configuration);
}

/**
* @return RefundRequestBuilder
*/
public function createRefundRequestBuilder()
{
return new RefundRequestBuilder($this->configuration);
}

/**
* @param RequestAbstract $request
* @param string $endpointUrl
Expand Down Expand Up @@ -89,4 +100,15 @@ public function makeLoyaltyInquiry(LoyaltyInquiryRequest $request)
$parser = new ResponseParser(new LoyaltyInquiryResponseParser(), $rawResponse);
return $parser->parse();
}

/**
* @param RefundRequest $request
* @return Response\RefundResponse
*/
public function makeRefund(RefundRequest $request)
{
$rawResponse = $this->sendRequest($request, $this->configuration->getRefundEndpointUrl());
$parser = new ResponseParser(new RefundResponseParser(), $rawResponse);
return $parser->parse();
}
}
177 changes: 177 additions & 0 deletions src/Payu/Component/Refund.php
@@ -0,0 +1,177 @@
<?php
namespace Payu\Component;

class Refund implements ComponentInterface
{
/**
* @var string
*/
private $merchant;

/**
* @var string
*/
private $orderRef;

/**
* @var float
*/
private $orderAmount;

/**
* @var string
*/
private $orderCurrency;

/**
* @var string
*/
private $irnDate;

/**
* @var float
*/
private $amount;

/**
* @var float
*/
private $loyaltyPointsAmount;

/**
* @param float $amount
*/
public function setAmount($amount)
{
$this->amount = $amount;
return $this;
}

/**
* @return float
*/
public function getAmount()
{
return $this->amount;
}

/**
* @param string $irnDate
*/
public function setIrnDate($irnDate)
{
$this->irnDate = $irnDate;
return $this;
}

/**
* @return string
*/
public function getIrnDate()
{
return $this->irnDate;
}

/**
* @param float $loyaltyPointsAmount
*/
public function setLoyaltyPointsAmount($loyaltyPointsAmount)
{
$this->loyaltyPointsAmount = $loyaltyPointsAmount;
return $this;
}

/**
* @return float
*/
public function getLoyaltyPointsAmount()
{
return $this->loyaltyPointsAmount;
}

/**
* @param string $merchant
*/
public function setMerchant($merchant)
{
$this->merchant = $merchant;
return $this;
}

/**
* @return string
*/
public function getMerchant()
{
return $this->merchant;
}

/**
* @param float $orderAmount
*/
public function setOrderAmount($orderAmount)
{
$this->orderAmount = $orderAmount;
return $this;
}

/**
* @return float
*/
public function getOrderAmount()
{
return $this->orderAmount;
}

/**
* @param string $orderCurrency
*/
public function setOrderCurrency($orderCurrency)
{
$this->orderCurrency = $orderCurrency;
return $this;
}

/**
* @return string
*/
public function getOrderCurrency()
{
return $this->orderCurrency;
}

/**
* @param string $orderRef
*/
public function setOrderRef($orderRef)
{
$this->orderRef = $orderRef;
return $this;
}

/**
* @return string
*/
public function getOrderRef()
{
return $this->orderRef;
}

public function __construct(
$merchant=null,
$orderRef=null,
$orderAmount=null,
$orderCurrency=null,
$irnDate=null,
$amount=null,
$loyaltyPointsAmount=null
) {
$this->merchant = $merchant;
$this->orderRef = $orderRef;
$this->orderAmount = $orderAmount;
$this->orderCurrency = $orderCurrency;
$this->irnDate = $irnDate;
$this->amount = $amount;
$this->loyaltyPointsAmount = $loyaltyPointsAmount;
}
}
33 changes: 32 additions & 1 deletion src/Payu/Configuration.php
Expand Up @@ -23,13 +23,26 @@ class Configuration
*/
private $loyaltyInquiryEndPointUrl;

/**
* @var string
*/
private $refundEndpointUrl;

/**
* @param string $merchantId
* @param string $secretKey
* @param string $paymentEndpointUrl
* @param string $loyaltyInquiryEndPointUrl
* @param string $refundEndpointUrl
*/
public function __construct($merchantId = null, $secretKey = null, $paymentEndpointUrl = null,
$loyaltyInquiryEndPointUrl = null)
$loyaltyInquiryEndPointUrl = null, $refundEndpointUrl=null)
{
$this->merchantId = $merchantId;
$this->secretKey = $secretKey;
$this->paymentEndpointUrl = $paymentEndpointUrl;
$this->loyaltyInquiryEndPointUrl = $loyaltyInquiryEndPointUrl;
$this->refundEndpointUrl = $refundEndpointUrl;
}

/**
Expand Down Expand Up @@ -103,4 +116,22 @@ public function getSecretKey()
{
return $this->secretKey;
}

/**
* @param string $refundEndpointUrl
* @return $this
*/
public function setRefundEndpointUrl($refundEndpointUrl)
{
$this->refundEndpointUrl = $refundEndpointUrl;
return $this;
}

/**
* @return string
*/
public function getRefundEndpointUrl()
{
return $this->refundEndpointUrl;
}
}
38 changes: 38 additions & 0 deletions src/Payu/Parser/RefundResponseParser.php
@@ -0,0 +1,38 @@
<?php
namespace Payu\Parser;

use Payu\Exception\BadResponseError;
use Payu\Response\RefundResponse;
use Payu\Response\ResponseAbstract;

class RefundResponseParser implements ParserInterface
{
/**
* @param string $rawData
* @throws \Payu\Exception\BadResponseError
* @return \Payu\Response\ResponseAbstract
*/
public function parse($rawData)
{
try {
$xml = new SimpleXMLElement($rawData);
} catch(Exception $e) {
throw new BadResponseError('Unexpected response received from provider. Response: ' . $rawData);
}

$row = $xml->EPAYMENT;
$explodedRow = explode('|', $row);

if(count($explodedRow) != 5 ) {
throw new BadResponseError('Unexpected response received from provider. Response: ' . $row);
}

list($orderRef, $code, $message, $irnDate, $orderHash) = $explodedRow;
$statusCode = trim((string) $message) == 'OK' ?
ResponseAbstract::STATUS_APPROVED : ResponseAbstract::STATUS_DECLINED;
$code = (string) $code;
$message = (string) $message;

return new RefundResponse($statusCode, $code, $message);
}
}

0 comments on commit f097bc8

Please sign in to comment.