Skip to content

Commit

Permalink
Update readme and added missing functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Buijsrogge committed Mar 15, 2017
1 parent 3bf2ea6 commit 765269f
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 50 deletions.
138 changes: 88 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ composer require sebudesign/buckaroo-json
require 'vendor/autoload.php';

use SeBuDesign\BuckarooJson\Transaction;
use SeBuDesign\BuckarooJson\TransactionStatus;
use SeBuDesign\BuckarooJson\Parts\IpAddress;
use SeBuDesign\BuckarooJson\Parts\Service;
use SeBuDesign\BuckarooJson\Parts\OriginalTransactionReference;
Expand Down Expand Up @@ -131,60 +132,97 @@ class Foo
$transaction->hasAdditionalParameter('name');

// Start the transaction
$transactionAction = $transaction->start();
$transactionResponse = $transaction->start();

var_dump(
$transactionAction->getTransactionKey(),
$transactionAction->getOrder(),
$transactionAction->getIssuingCountry(),
$transactionAction->getInvoice(),
$transactionAction->getServiceCode(),
$transactionAction->getCurrency(),
$transactionAction->getAmountDebit(),
$transactionAction->getAmountCredit(),
$transactionAction->getTransactionType(),
$transactionAction->getMutationType(),
$transactionAction->getRelatedTransactions(),
$transactionAction->getRelatedTransactions()[1]->getType(),
$transactionAction->getRelatedTransactions()[1]->getTransactionKey(),
$transactionAction->getConsumerMessage(),
$transactionAction->getConsumerMessage()->hasToRead(),
$transactionAction->getConsumerMessage()->getCulture(),
$transactionAction->getConsumerMessage()->getTitle(),
$transactionAction->getConsumerMessage()->getPlainText(),
$transactionAction->getConsumerMessage()->getHtmlText(),
$transactionAction->isTest(),
$transactionAction->isFirstRecurring(),
$transactionAction->isRecurring(),
$transactionAction->getClientName(),
$transactionAction->getPayerHash(),
$transactionAction->getPaymentKey(),
$transactionAction->getStatus()->getCode(),
$transactionAction->getStatus()->getDescription(),
$transactionAction->getSubStatus()->getCode(),
$transactionAction->getSubStatus()->getDescription(),
$transactionAction->getStatusChangedAt(),
$transactionAction->getRequiredAction()->hasToRedirect(),
$transactionAction->getRequiredAction()->getName(),
$transactionAction->getRequiredAction()->isDeprecated(),
$transactionAction->getRequiredAction()->getRedirectUrl(),
$transactionAction->getRequiredAction()->getRequestedInformation(),
$transactionAction->getRequiredAction()->getPayRemainderDetails()->getRemainderAmount(),
$transactionAction->getRequiredAction()->getPayRemainderDetails()->getCurrency(),
$transactionAction->getServices(),
$transactionAction->getServices()[1]->getName(),
$transactionAction->getServices()[1]->getAction(),
$transactionAction->getServices()[1]->getVersion(),
$transactionAction->getServices()[1]->getParameters(),
$transactionAction->getCustomParameters(),
$transactionAction->getAdditionalParameters(),
$transactionAction->hasErrors(),
$transactionAction->getErrors(),
$transactionResponse->getTransactionKey(),
$transactionResponse->getOrder(),
$transactionResponse->getIssuingCountry(),
$transactionResponse->getInvoice(),
$transactionResponse->getServiceCode(),
$transactionResponse->getCurrency(),
$transactionResponse->getAmountDebit(),
$transactionResponse->getAmountCredit(),
$transactionResponse->getTransactionType(),
$transactionResponse->getMutationType(),
$transactionResponse->getRelatedTransactions(),
$transactionResponse->hasConsumerMessage(),
$transactionResponse->hasToReadConsumerMessage(),
$transactionResponse->getConsumerMessage(),
$transactionResponse->isTest(),
$transactionResponse->hasStartedRecurringPayment(),
$transactionResponse->isRecurringPayment(),
$transactionResponse->isCancelable(),
$transactionResponse->getCustomerName(),
$transactionResponse->getPayerHash(),
$transactionResponse->getPaymentKey(),
$transactionResponse->getStatusCode(),
$transactionResponse->getStatusSubCode(),
$transactionResponse->getDateTimeOfStatusChange(),
$transactionResponse->hasRequiredAction(),
$transactionResponse->getRequestedInformation(),
$transactionResponse->hasToRedirect(),
$transactionResponse->hasToPayRemainder(),
$transactionResponse->getRemainderAmount(),
$transactionResponse->getRemainderCurrency(),
$transactionResponse->getRemainderGroupTransaction(),
$transactionResponse->getRedirectUrl(),
$transactionResponse->getServices(),
$transactionResponse->getService('name'),
$transactionResponse->getServiceParameters('name'),
$transactionResponse->getCustomParameters(),
$transactionResponse->getAdditionalParameters(),
$transactionResponse->hasErrors(),
$transactionResponse->getErrors()
);
}

public function getTransactionStatus()
{
$transactionStatus = new TransactionStatus('website-key', 'secret-key');
$transactionResponse = $transactionStatus->get('transaction-key');

if ($transactionAction->getRequiredAction()->hasToRedirect()) {
header('Location: ' . $transactionAction->getRequiredAction()->getRedirectUrl());
}
var_dump(
$transactionResponse->getTransactionKey(),
$transactionResponse->getOrder(),
$transactionResponse->getIssuingCountry(),
$transactionResponse->getInvoice(),
$transactionResponse->getServiceCode(),
$transactionResponse->getCurrency(),
$transactionResponse->getAmountDebit(),
$transactionResponse->getAmountCredit(),
$transactionResponse->getTransactionType(),
$transactionResponse->getMutationType(),
$transactionResponse->getRelatedTransactions(),
$transactionResponse->hasConsumerMessage(),
$transactionResponse->hasToReadConsumerMessage(),
$transactionResponse->getConsumerMessage(),
$transactionResponse->isTest(),
$transactionResponse->hasStartedRecurringPayment(),
$transactionResponse->isRecurringPayment(),
$transactionResponse->isCancelable(),
$transactionResponse->getCustomerName(),
$transactionResponse->getPayerHash(),
$transactionResponse->getPaymentKey(),
$transactionResponse->getStatusCode(),
$transactionResponse->getStatusSubCode(),
$transactionResponse->getDateTimeOfStatusChange(),
$transactionResponse->hasRequiredAction(),
$transactionResponse->getRequestedInformation(),
$transactionResponse->hasToRedirect(),
$transactionResponse->hasToPayRemainder(),
$transactionResponse->getRemainderAmount(),
$transactionResponse->getRemainderCurrency(),
$transactionResponse->getRemainderGroupTransaction(),
$transactionResponse->getRedirectUrl(),
$transactionResponse->getServices(),
$transactionResponse->getService('name'),
$transactionResponse->getServiceParameters('name'),
$transactionResponse->getCustomParameters(),
$transactionResponse->getAdditionalParameters(),
$transactionResponse->hasErrors(),
$transactionResponse->getErrors()
);
}
}

Expand Down
57 changes: 57 additions & 0 deletions src/Responses/TransactionResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ public function getStatusCode()
return $iCode;
}

/**
* Get the current status code
*
* @return int
*/
public function getStatusSubCode()
{
$iCode = 0;
if ($this->hasStatusSubCode()) {
$iCode = $this->aResponseData['Status']['SubCode']['Code'];
}

return $iCode;
}

/**
* Does the response have a status code?
*
Expand Down Expand Up @@ -392,6 +407,48 @@ public function isCancelable()
return (!isset($this->aResponseData['IsCancelable']) || is_null($this->aResponseData['IsCancelable']) ? false : $this->aResponseData['IsCancelable']);
}

/**
* Is there a consumer message?
*
* @return bool
*/
public function hasConsumerMessage()
{
return (!isset($this->aResponseData['ConsumerMessage']) || is_null($this->aResponseData['ConsumerMessage']) ? false : true);
}

/**
* Does the client need to read the message?
*
* @return bool
*/
public function hasToReadConsumerMessage()
{
$bHasToRead = false;

if ($this->hasConsumerMessage()) {
$bHasToRead = (boolean) $this->aResponseData['ConsumerMessage']['MustRead'];
}

return $bHasToRead;
}

/**
* Get the consumer message
*
* @return bool|array
*/
public function getConsumerMessage()
{
$mConsumerMessage = false;

if ($this->hasConsumerMessage()) {
$mConsumerMessage = $this->aResponseData['ConsumerMessage'];
}

return $mConsumerMessage;
}

/**
* Check if there are any errors from a specific type
*
Expand Down
17 changes: 17 additions & 0 deletions tests/integration/StartTransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ public function it_should_return_a_valid_transaction_request_response()
$this->assertFalse(
$oTransactionResponse->hasErrors()
);
$this->assertNotEquals(
0,
$oTransactionResponse->getStatusCode()
);
$this->assertNotEquals(
0,
$oTransactionResponse->getStatusSubCode()
);
$this->assertInstanceOf(
\DateTime::class,
$oTransactionResponse->getDateTimeOfStatusChange()
Expand Down Expand Up @@ -157,5 +165,14 @@ public function it_should_return_a_valid_transaction_request_response()
$this->assertFalse(
$oTransactionResponse->isCancelable()
);
$this->assertFalse(
$oTransactionResponse->hasConsumerMessage()
);
$this->assertFalse(
$oTransactionResponse->hasToReadConsumerMessage()
);
$this->assertFalse(
$oTransactionResponse->getConsumerMessage()
);
}
}

0 comments on commit 765269f

Please sign in to comment.