-
Notifications
You must be signed in to change notification settings - Fork 125
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
Showing
12 changed files
with
314 additions
and
2 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
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,14 @@ | ||
<?php | ||
|
||
require_once('config.php'); | ||
|
||
# create request class | ||
$request = new \Iyzipay\Request\CreateRefundToBalanceRequest(); | ||
$request->setPaymentId("544316496"); | ||
$request->setCallbackUrl("https://www.callback"); | ||
|
||
# make request | ||
$refundToBalance = \Iyzipay\Model\RefundToBalance::create($request, Config::options()); | ||
|
||
# print result | ||
print_r($refundToBalance); |
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,25 @@ | ||
<?php | ||
|
||
namespace Iyzipay\Model\Mapper; | ||
|
||
use Iyzipay\Model\RefundToBalance; | ||
|
||
class RefundToBalanceMapper extends RefundToBalanceResourceMapper | ||
{ | ||
public static function create($rawResult = null) | ||
{ | ||
return new RefundToBalanceMapper($rawResult); | ||
} | ||
|
||
public function mapRefundToBalanceFrom(RefundToBalance $refundToBalance, $jsonObject) | ||
{ | ||
parent::mapRefundToBalanceResourceFrom($refundToBalance, $jsonObject); | ||
return $refundToBalance; | ||
} | ||
|
||
public function mapRefundToBalance(RefundToBalance $refundToBalance) | ||
{ | ||
|
||
return $this->mapRefundToBalanceFrom($refundToBalance, $this->jsonObject); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/Iyzipay/Model/Mapper/RefundToBalanceResourceMapper.php
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,32 @@ | ||
<?php | ||
|
||
namespace Iyzipay\Model\Mapper; | ||
|
||
use Iyzipay\Model\RefundToBalanceResource; | ||
|
||
class RefundToBalanceResourceMapper extends IyzipayResourceMapper | ||
{ | ||
public static function create($rawResult = null) | ||
{ | ||
return new RefundToBalanceResourceMapper($rawResult); | ||
} | ||
|
||
public function mapRefundToBalanceResourceFrom(RefundToBalanceResource $refundToBalanceResource, $jsonObject) | ||
{ | ||
parent::mapResourceFrom($refundToBalanceResource, $jsonObject); | ||
|
||
if (isset($jsonObject->token)) { | ||
$refundToBalanceResource->setToken($jsonObject->token); | ||
} | ||
if (isset($jsonObject->url)) { | ||
$refundToBalanceResource->setUrl($jsonObject->url); | ||
} | ||
|
||
return $refundToBalanceResource; | ||
} | ||
|
||
public function mapRefundToBalanceResource(RefundToBalanceResource $refundToBalanceResource) | ||
{ | ||
return $this->mapRefundToBalanceResourceFrom($refundToBalanceResource, $this->jsonObject); | ||
} | ||
} |
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,17 @@ | ||
<?php | ||
|
||
namespace Iyzipay\Model; | ||
|
||
use Iyzipay\Model\Mapper\RefundToBalanceMapper; | ||
use Iyzipay\Options; | ||
use Iyzipay\Request\CreateRefundToBalanceRequest; | ||
|
||
class RefundToBalance extends RefundToBalanceResource | ||
{ | ||
public static function create(CreateRefundToBalanceRequest $request, Options $options) | ||
{ | ||
$rawResult = parent::httpClient()->post($options->getBaseUrl() . "/payment/iyzipos/refund-to-balance/init", parent::getHttpHeaders($request, $options), $request->toJsonString()); | ||
|
||
return RefundToBalanceMapper::create($rawResult)->jsonDecode()->mapRefundToBalance(new RefundToBalance()); | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
|
||
namespace Iyzipay\Model; | ||
|
||
use Iyzipay\IyzipayResource; | ||
|
||
class RefundToBalanceResource extends IyzipayResource | ||
{ | ||
private $token; | ||
private $url; | ||
|
||
public function getToken() | ||
{ | ||
return $this->token; | ||
} | ||
|
||
public function setToken($token) | ||
{ | ||
$this->token = $token; | ||
} | ||
|
||
public function getUrl() | ||
{ | ||
return $this->url; | ||
} | ||
|
||
public function setUrl($url) | ||
{ | ||
$this->url = $url; | ||
} | ||
} |
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,50 @@ | ||
<?php | ||
|
||
namespace Iyzipay\Request; | ||
|
||
use Iyzipay\JsonBuilder; | ||
use Iyzipay\Request; | ||
use Iyzipay\RequestStringBuilder; | ||
|
||
class CreateRefundToBalanceRequest extends Request | ||
{ | ||
private $paymentId; | ||
private $callbackUrl; | ||
|
||
public function getPaymentId() | ||
{ | ||
return $this->paymentId; | ||
} | ||
|
||
public function setPaymentId($paymentId) | ||
{ | ||
$this->paymentId = $paymentId; | ||
} | ||
|
||
public function getCallbackUrl() | ||
{ | ||
return $this->callbackUrl; | ||
} | ||
|
||
public function setCallbackUrl($callbackUrl) | ||
{ | ||
$this->callbackUrl = $callbackUrl; | ||
} | ||
|
||
public function getJsonObject() | ||
{ | ||
return JsonBuilder::fromJsonObject(parent::getJsonObject()) | ||
->add("paymentId", $this->getPaymentId()) | ||
->add("callbackUrl", $this->getCallbackUrl()) | ||
->getObject(); | ||
} | ||
|
||
public function toPKIRequestString() | ||
{ | ||
return RequestStringBuilder::create() | ||
->appendSuper(parent::toPKIRequestString()) | ||
->append("paymentId", $this->getPaymentId()) | ||
->append("callbackUrl", $this->getCallbackUrl()) | ||
->getRequestString(); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
tests/Iyzipay/Tests/Model/Mapper/RefundToBalanceMapperTest.php
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,31 @@ | ||
<?php | ||
|
||
namespace Iyzipay\Tests\Model\Mapper; | ||
|
||
use Iyzipay\Model\Mapper\RefundToBalanceMapper; | ||
use Iyzipay\Model\RefundToBalance; | ||
use Iyzipay\Tests\TestCase; | ||
|
||
class RefundToBalanceMapperTest extends TestCase | ||
{ | ||
public function test_should_map_refund_to_balance_mapper() | ||
{ | ||
$json = $this->retrieveJsonFile("refund_to_balance.json"); | ||
|
||
$refundToBalance = RefundToBalanceMapper::create($json)->jsonDecode()->mapRefundToBalance(new RefundToBalance()); | ||
|
||
$this->assertNotEmpty($refundToBalance); | ||
$this->assertEquals("123456", $refundToBalance->getToken()); | ||
$this->assertEquals("https://url", $refundToBalance->getUrl()); | ||
$this->assertEquals("failure", $refundToBalance->getStatus()); | ||
$this->assertEquals("10000", $refundToBalance->getErrorCode()); | ||
$this->assertEquals("error_message", $refundToBalance->getErrorMessage()); | ||
$this->assertEquals("ERROR_GROUP", $refundToBalance->getErrorGroup()); | ||
$this->assertEquals("1458545234852", $refundToBalance->getSystemTime()); | ||
$this->assertEquals("tr", $refundToBalance->getLocale()); | ||
$this->assertEquals("123456", $refundToBalance->getConversationId()); | ||
$this->assertJson($refundToBalance->getRawResult()); | ||
$this->assertJsonStringEqualsJsonString($json, $refundToBalance->getRawResult()); | ||
|
||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
tests/Iyzipay/Tests/Model/Mapper/RefundToBalanceResourceMapperTest.php
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,31 @@ | ||
<?php | ||
|
||
namespace Iyzipay\Tests\Model\Mapper; | ||
|
||
use Iyzipay\Model\Mapper\RefundToBalanceResourceMapper; | ||
use Iyzipay\Model\RefundToBalanceResource; | ||
use Iyzipay\Tests\TestCase; | ||
|
||
class RefundToBalanceResourceMapperTest extends TestCase | ||
{ | ||
public function test_should_map_refund_to_balance_resource() | ||
{ | ||
$json = $this->retrieveJsonFile("refund_to_balance.json"); | ||
|
||
$refundToBalance = RefundToBalanceResourceMapper::create($json)->jsonDecode()->mapRefundToBalanceResource(new RefundToBalanceResource()); | ||
|
||
$this->assertNotEmpty($refundToBalance); | ||
$this->assertEquals("123456", $refundToBalance->getToken()); | ||
$this->assertEquals("https://url", $refundToBalance->getUrl()); | ||
$this->assertEquals("failure", $refundToBalance->getStatus()); | ||
$this->assertEquals("10000", $refundToBalance->getErrorCode()); | ||
$this->assertEquals("error_message", $refundToBalance->getErrorMessage()); | ||
$this->assertEquals("ERROR_GROUP", $refundToBalance->getErrorGroup()); | ||
$this->assertEquals("1458545234852", $refundToBalance->getSystemTime()); | ||
$this->assertEquals("tr", $refundToBalance->getLocale()); | ||
$this->assertEquals("123456", $refundToBalance->getConversationId()); | ||
$this->assertJson($refundToBalance->getRawResult()); | ||
$this->assertJsonStringEqualsJsonString($json, $refundToBalance->getRawResult()); | ||
|
||
} | ||
} |
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,19 @@ | ||
<?php | ||
|
||
namespace Iyzipay\Tests\Model; | ||
|
||
use Iyzipay\Model\RefundToBalance; | ||
use Iyzipay\Request\CreateRefundToBalanceRequest; | ||
use Iyzipay\Tests\IyzipayResourceTestCase; | ||
|
||
class RefundToBalanceTest extends IyzipayResourceTestCase | ||
{ | ||
public function test_should_refund_to_balance() | ||
{ | ||
$this->expectHttpPost(); | ||
|
||
$refundToBalance = RefundToBalance::create(new CreateRefundToBalanceRequest(), $this->options); | ||
|
||
$this->verifyResource($refundToBalance); | ||
} | ||
} |
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,51 @@ | ||
<?php | ||
|
||
namespace Iyzipay\Tests\Request; | ||
|
||
use Iyzipay\Request\CreateRefundToBalanceRequest; | ||
use Iyzipay\Tests\TestCase; | ||
|
||
class CreateRefundToBalanceRequestTest extends TestCase | ||
{ | ||
public function test_should_get_json_object() | ||
{ | ||
$request = $this->prepareRequest(); | ||
$jsonObject = $request->getJsonObject(); | ||
|
||
|
||
$this->assertEquals("123456", $jsonObject["paymentId"]); | ||
$this->assertEquals("https://callback", $jsonObject["callbackUrl"]); | ||
} | ||
|
||
public function test_should_convert_to_pki_request_string() | ||
{ | ||
$request = $this->prepareRequest(); | ||
|
||
$str = "[paymentId=123456," . | ||
"callbackUrl=https://callback]"; | ||
|
||
$this->assertEquals($str, $request->toPKIRequestString()); | ||
} | ||
|
||
public function test_should_get_json_string() | ||
{ | ||
$request = $this->prepareRequest(); | ||
|
||
$json = ' | ||
{ | ||
"paymentId":"123456", | ||
"callbackUrl":"https://callback" | ||
}'; | ||
|
||
$this->assertJson($request->toJsonString()); | ||
$this->assertJsonStringEqualsJsonString($json, $request->toJsonString()); | ||
} | ||
|
||
private function prepareRequest() | ||
{ | ||
$request = new CreateRefundToBalanceRequest(); | ||
$request->setPaymentId("123456"); | ||
$request->setCallbackUrl("https://callback"); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"token":"123456", | ||
"url":"https://url", | ||
"status": "failure", | ||
"errorCode": 10000, | ||
"errorMessage": "error_message", | ||
"errorGroup": "ERROR_GROUP", | ||
"locale": "tr", | ||
"systemTime": "1458545234852", | ||
"conversationId": "123456" | ||
} |