Skip to content

Commit

Permalink
Fixes ReportingPaymentDetail query string issue mentioned in Pull Req…
Browse files Browse the repository at this point in the history
…uest #144
  • Loading branch information
osman-keser committed Mar 20, 2024
1 parent 6ae7a29 commit ce4a4a9
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 86 deletions.
4 changes: 1 addition & 3 deletions samples/reporting_payment_detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

$request = new \Iyzipay\Request\ReportingPaymentDetailRequest();
$request->setPaymentConversationId("123456789");

$request->setPaymentId('12345678');

$result = \Iyzipay\Model\ReportingPaymentDetail::create($request, Config::options());

print_r($result);


27 changes: 16 additions & 11 deletions src/Iyzipay/Request/ReportingPaymentDetailRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,29 @@
use Iyzipay\JsonBuilder;
use Iyzipay\Request;

class ReportingPaymentDetailRequest extends Request
{
private $paymentConversationId;
class ReportingPaymentDetailRequest extends Request {
private string $paymentConversationId;
private string $paymentId;

public function getPaymentConversationId()
{
return $this->paymentConversationId;
public function getPaymentConversationId(): ?string {
return $this->paymentConversationId ?? null;
}

public function setPaymentConversationId($paymentConversationId)
{
public function setPaymentConversationId(string $paymentConversationId): void {
$this->paymentConversationId = $paymentConversationId;
}

public function getJsonObject()
{
public function getPaymentId(): ?string {
return $this->paymentId ?? null;
}

public function setPaymentId(string $paymentId): void {
$this->paymentId = $paymentId;
}

public function getJsonObject() {
return JsonBuilder::fromJsonObject(parent::getJsonObject())
->add("paymentConversationId", $this->getPaymentConversationId())
->getObject();
}
}
}
125 changes: 60 additions & 65 deletions src/Iyzipay/RequestStringBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,22 @@

namespace Iyzipay;

class RequestStringBuilder
{
class RequestStringBuilder {
private $requestString;

function __construct($requestString)
{
function __construct($requestString) {
$this->requestString = $requestString;
}

public static function create()
{
public static function create() {
return new RequestStringBuilder("");
}

/**
* @param $superRequestString
* @return RequestStringBuilder
*/
public function appendSuper($superRequestString)
{
public function appendSuper($superRequestString) {
if (isset($superRequestString)) {
$superRequestString = substr($superRequestString, 1);
$superRequestString = substr($superRequestString, 0, -1);
Expand All @@ -38,8 +34,7 @@ public function appendSuper($superRequestString)
* @param $value
* @return RequestStringBuilder
*/
public function append($key, $value = null)
{
public function append($key, $value = null) {
if (isset($value)) {
if ($value instanceof RequestStringConvertible) {
$this->appendKeyValue($key, $value->toPKIRequestString());
Expand All @@ -55,8 +50,7 @@ public function append($key, $value = null)
* @param $value
* @return RequestStringBuilder
*/
public function appendPrice($key, $value = null)
{
public function appendPrice($key, $value = null) {
if (isset($value)) {
$this->appendKeyValue($key, RequestFormatter::formatPrice($value));
}
Expand All @@ -68,8 +62,7 @@ public function appendPrice($key, $value = null)
* @param array $array
* @return RequestStringBuilder
*/
public function appendArray($key, array $array = null)
{
public function appendArray($key, array $array = null) {
if (isset($array)) {
$appendedValue = "";
foreach ($array as $value) {
Expand All @@ -90,8 +83,7 @@ public function appendArray($key, array $array = null)
* @param $value
* @return RequestStringBuilder
*/
private function appendKeyValue($key, $value)
{
private function appendKeyValue($key, $value) {
if (isset($value)) {
$this->requestString = $this->requestString . $key . "=" . $value . ",";
}
Expand All @@ -103,8 +95,7 @@ private function appendKeyValue($key, $value)
* @param $value
* @return RequestStringBuilder
*/
private function appendKeyValueArray($key, $value)
{
private function appendKeyValueArray($key, $value) {
if (isset($value)) {
$value = substr($value, 0, -2);
$this->requestString = $this->requestString . $key . "=[" . $value . "],";
Expand All @@ -115,136 +106,140 @@ private function appendKeyValueArray($key, $value)
/**
* @return RequestStringBuilder
*/
private function appendPrefix()
{
private function appendPrefix() {
$this->requestString = "[" . $this->requestString . "]";
return $this;
}

/**
* @return RequestStringBuilder
*/
private function removeTrailingComma()
{
private function removeTrailingComma() {
$this->requestString = substr($this->requestString, 0, -1);
return $this;
}

public function getRequestString()
{
public function getRequestString() {
$this->removeTrailingComma();
$this->appendPrefix();
return $this->requestString;
}

public static function requestToStringQuery(Request $request, $type = null)
{
public static function requestToStringQuery(Request $request, $type = null) {

$stringQuery = false;

if($request->getConversationId()) {
if ($request->getConversationId()) {
$stringQuery = "?conversationId=" . $request->getConversationId();
}

if($request->getLocale()) {
if ($request->getLocale()) {
$stringQuery .= "&locale=" . $request->getLocale();
}

if ($type == 'locale') {
$stringQuery = "?locale=" . $request->getLocale();
}

if($type == 'defaultParams' ) {
if($request->getConversationId()) {
if ($type == 'defaultParams') {
if ($request->getConversationId()) {
$stringQuery = "?conversationId=" . $request->getConversationId();
$stringQuery .= ($request->getLocale()) ? ("&locale=" . $request->getLocale()) : '';
}else{
} else {
$stringQuery = ($request->getLocale()) ? ("?locale=" . $request->getLocale()) : '';
}
}

if($type == 'reporting') {
if($request->getPaymentConversationId()) {
$stringQuery .= "?paymentConversationId=" . $request->getPaymentConversationId();
if ($type == 'reporting') {
$hasPaymentConversationId = $request->getPaymentConversationId() ?? false;

if ($hasPaymentConversationId) {
$stringQuery = "?paymentConversationId=" . $request->getPaymentConversationId();
}

if ($request->getPaymentId()) {
$querySign = $hasPaymentConversationId ? '&' : '?';
$stringQuery = $hasPaymentConversationId ? $stringQuery . $querySign : $querySign;
$stringQuery .= 'paymentId=' . $request->getPaymentId();
}
}

if($type == 'reportingTransaction') {
if ($type == 'reportingTransaction') {

if($request->getTransactionDate()) {
if ($request->getTransactionDate()) {
$stringQuery .= "&transactionDate=" . $request->getTransactionDate();
}
if ($request->getPage()) {
$stringQuery .= "&page=" . $request->getPage();
}
}

if($type == 'reportingScrollTransaction') {
if($request->getDocumentScrollVoSortingOrder()) {
if ($type == 'reportingScrollTransaction') {
if ($request->getDocumentScrollVoSortingOrder()) {
$stringQuery = '?documentScrollVoSortingOrder=' . $request->getDocumentScrollVoSortingOrder();
}

if($request->getTransactionDate()) {
if ($request->getTransactionDate()) {
$stringQuery .= "&transactionDate=" . $request->getTransactionDate();
}

if($request->getLastId()) {
if ($request->getLastId()) {
$stringQuery .= '&lastId=' . $request->getLastId();
}
}

if($type == 'subscriptionItems' ) {
if ($type == 'subscriptionItems') {
if ($request->getPage()) {
$stringQuery = "?page=" . $request->getPage();
}
if ($request->getCount()) {
$stringQuery .= "&count=" . $request->getCount();
}
if($request->getConversationId()) {
if ($request->getConversationId()) {
$stringQuery .= "&conversationId=" . $request->getConversationId();
}
if($request->getLocale()) {
if ($request->getLocale()) {
$stringQuery .= "&locale=" . $request->getLocale();
}
}

if($type == 'searchSubscription') {
if($request->getPage()){
$stringQuery = "?page=".$request->getPage();
if ($type == 'searchSubscription') {
if ($request->getPage()) {
$stringQuery = "?page=" . $request->getPage();
}
if($request->getCount()){
$stringQuery .= "&count=".$request->getCount();
if ($request->getCount()) {
$stringQuery .= "&count=" . $request->getCount();
}
if($request->getSubscriptionReferenceCode()){
$stringQuery .= "&subscriptionReferenceCode=".$request->getSubscriptionReferenceCode();
if ($request->getSubscriptionReferenceCode()) {
$stringQuery .= "&subscriptionReferenceCode=" . $request->getSubscriptionReferenceCode();
}
if($request->getParentReferenceCode()){
$stringQuery .= "&parentReferenceCode=".$request->getParentReferenceCode();
if ($request->getParentReferenceCode()) {
$stringQuery .= "&parentReferenceCode=" . $request->getParentReferenceCode();
}
if($request->getCustomerReferenceCode()){
$stringQuery .= "&customerReferenceCode=".$request->getCustomerReferenceCode();
if ($request->getCustomerReferenceCode()) {
$stringQuery .= "&customerReferenceCode=" . $request->getCustomerReferenceCode();
}
if($request->getPricingPlanReferenceCode()){
$stringQuery .= "&pricingPlanReferenceCode=".$request->getPricingPlanReferenceCode();
if ($request->getPricingPlanReferenceCode()) {
$stringQuery .= "&pricingPlanReferenceCode=" . $request->getPricingPlanReferenceCode();
}
if($request->getSubscriptionStatus()){
$stringQuery .= "&subscriptionStatus=".$request->getSubscriptionStatus();
if ($request->getSubscriptionStatus()) {
$stringQuery .= "&subscriptionStatus=" . $request->getSubscriptionStatus();
}
if($request->getStartDate()){
$stringQuery .= "&startDate=".$request->getStartDate();
if ($request->getStartDate()) {
$stringQuery .= "&startDate=" . $request->getStartDate();
}
if($request->getEndDate()){
$stringQuery .= "&endDate=".$request->getEndDate();
if ($request->getEndDate()) {
$stringQuery .= "&endDate=" . $request->getEndDate();
}
if($request->getConversationId()) {
if ($request->getConversationId()) {
$stringQuery .= "&conversationId=" . $request->getConversationId();
}
if($request->getLocale()) {
if ($request->getLocale()) {
$stringQuery .= "&locale=" . $request->getLocale();
}
}

if($type == 'pages') {
if ($type == 'pages') {
if ($request->getPage()) {
$stringQuery .= "&page=" . $request->getPage();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@ public function test_should_report_payment_detail_request_object()
$request = $this->prepareRequest();
$jsonObject = $request->getJsonObject();

$this->assertEquals(Locale::TR, $jsonObject["locale"]);
$this->assertEquals("123456789", $jsonObject["conversationId"]);
$this->assertEquals("123456789", $jsonObject["paymentConversationId"]);
$this->assertEquals("12345678", $jsonObject['paymentId']);
}

private function prepareRequest()
{
$request = new ReportingPaymentDetailRequest();
$request->setLocale(\Iyzipay\Model\Locale::TR);
$request->setConversationId("123456789");
$request->setPaymentConversationId("123456789");
$request->setPaymentId("12345678");

return $request;
}
Expand Down
5 changes: 2 additions & 3 deletions tests/Iyzipay/Tests/RequestStringBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ public function test_should_request_string_query_pages()
public function test_should_request_string_query_reporting()
{
$request = new \Iyzipay\Request\ReportingPaymentDetailRequest();
$request->setLocale(Locale::TR);
$request->setConversationId("123456789");
$request->setPaymentConversationId('123456789');
$request->setPaymentId('12345678');
$result = RequestStringBuilder::requestToStringQuery($request, 'reporting');

$this->assertEquals("?conversationId=123456789&locale=tr?paymentConversationId=123456789", $result);
$this->assertEquals("?paymentConversationId=123456789&paymentId=12345678", $result);
}

public function test_should_request_string_query_reporting_transaction()
Expand Down

0 comments on commit ce4a4a9

Please sign in to comment.