Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d9d6c13
commit f097bc8
Showing
15 changed files
with
452 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
Oops, something went wrong.