Skip to content

Commit

Permalink
Merge f64e157 into 560d091
Browse files Browse the repository at this point in the history
  • Loading branch information
mehmetselim committed Oct 11, 2019
2 parents 560d091 + f64e157 commit 69b9239
Show file tree
Hide file tree
Showing 12 changed files with 314 additions and 2 deletions.
4 changes: 2 additions & 2 deletions samples/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class Config
public static function options()
{
$options = new \Iyzipay\Options();
$options->setApiKey("");
$options->setSecretKey("");
$options->setApiKey("api-key");
$options->setSecretKey("secret-key");
$options->setBaseUrl("https://sandbox-api.iyzipay.com");
return $options;
}
Expand Down
14 changes: 14 additions & 0 deletions samples/refund_to_balance.php
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);
25 changes: 25 additions & 0 deletions src/Iyzipay/Model/Mapper/RefundToBalanceMapper.php
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 src/Iyzipay/Model/Mapper/RefundToBalanceResourceMapper.php
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);
}
}
17 changes: 17 additions & 0 deletions src/Iyzipay/Model/RefundToBalance.php
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());
}
}
31 changes: 31 additions & 0 deletions src/Iyzipay/Model/RefundToBalanceResource.php
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;
}
}
50 changes: 50 additions & 0 deletions src/Iyzipay/Request/CreateRefundToBalanceRequest.php
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 tests/Iyzipay/Tests/Model/Mapper/RefundToBalanceMapperTest.php
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());

}
}
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());

}
}
19 changes: 19 additions & 0 deletions tests/Iyzipay/Tests/Model/RefundToBalanceTest.php
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);
}
}
51 changes: 51 additions & 0 deletions tests/Iyzipay/Tests/Request/CreateRefundToBalanceTest.php
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;
}
}
11 changes: 11 additions & 0 deletions tests/Iyzipay/Tests/mock/refund_to_balance.json
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"
}

0 comments on commit 69b9239

Please sign in to comment.