Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ jobs:
steps:
- name: "Checkout"
uses: "actions/checkout@v4"

with:
# Fetch arbitrary more-than-one commit or Scrutinizer will error
fetch-depth: 10
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
Expand Down Expand Up @@ -63,3 +65,11 @@ jobs:
- name: "Tests (PHPUnit 10+)"
if: ${{ matrix.php-version >= '8.1' }}
run: "vendor/bin/phpunit"

- name: Upload Scrutinizer coverage
continue-on-error: true
uses: sudo-bot/action-scrutinizer@latest
# Do not run this step on forked versions of the main repository (example: contributor forks)
if: github.repository == 'patronbase/omnipay-bpoint'
with:
cli-args: "--format=php-clover build/logs/clover.xml --revision=${{ github.event.pull_request.head.sha || github.sha }}"
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
"omnipay/common": "^3.1"
},
"require-dev": {
"omnipay/tests": "^4.1",
"omnipay/tests": "^4.2",
"squizlabs/php_codesniffer": "^3.5",
"symfony/psr-http-message-bridge": "~1.1.0|^2.0",
"http-interop/http-factory-guzzle": "^1.1"
"symfony/psr-http-message-bridge": "~1.1.1|^2.0",
"guzzlehttp/psr7": "^2.0"
},
"scripts": {
"test": "phpunit",
Expand Down
16 changes: 13 additions & 3 deletions src/Message/CompletePurchaseResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function isSuccessful()
*/
public function getTransactionReference()
{
return isset($this->data['AuthoriseId']) ? $this->data['AuthoriseId'] : null;
return $this->data['AuthoriseId'] ?? null;
}

/**
Expand All @@ -37,7 +37,7 @@ public function getTransactionReference()
*/
public function getMessage()
{
return isset($this->data['ResponseText']) ? $this->data['ResponseText'] : null;
return $this->data['ResponseText'] ?? null;
}

/**
Expand All @@ -47,6 +47,16 @@ public function getMessage()
*/
public function getCardType()
{
return isset($this->data['CardType']) ? $this->data['CardType'] : null;
return $this->data['CardType'] ?? null;
}

/**
* Get the card reference (payment token) if available
*
* @return null|string
*/
public function getCardReference()
{
return $this->data['DVToken'] ?? null;
}
}
123 changes: 116 additions & 7 deletions src/Message/PurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ public function setMerchantNumber($value)
return $this->setParameter('merchantNumber', $value);
}

public function getCreateToken()
{
return $this->getParameter('createToken');
}

public function setCreateToken($value)
{
return $this->setParameter('createToken', $value);
}

public function getMerchantShortName()
{
return $this->getParameter('merchantShortName');
Expand All @@ -55,6 +65,21 @@ public function setMerchantShortName($value)
return $this->setParameter('merchantShortName', $value);
}

public function getBillerCode()
{
return $this->getParameter('billerCode');
}

/**
* Set biller code for the transaction (differentiate income streams); required for using stored card tokens
*
* @param string $value String, max 50 characters
*/
public function setBillerCode($value)
{
return $this->setParameter('billerCode', $value);
}

public function getCustomerReferenceNumber1()
{
return $this->getParameter('customerReferenceNumber1');
Expand All @@ -63,7 +88,7 @@ public function getCustomerReferenceNumber1()
/**
* Set customer configurable reference #1
*
* @param bool $value String, max 50 characters
* @param string $value String, max 50 characters
*/
public function setCustomerReferenceNumber1($value)
{
Expand All @@ -78,7 +103,7 @@ public function getCustomerReferenceNumber2()
/**
* Set customer configurable reference #2
*
* @param bool $value String, max 50 characters
* @param string $value String, max 50 characters
*/
public function setCustomerReferenceNumber2($value)
{
Expand All @@ -93,26 +118,91 @@ public function getCustomerReferenceNumber3()
/**
* Set customer configurable reference #3
*
* @param bool $value String, max 50 characters
* @param string $value String, max 50 characters
*/
public function setCustomerReferenceNumber3($value)
{
return $this->setParameter('customerReferenceNumber3', $value);
}

public function getHideBillerCode()
{
return $this->getParameter('hideBillerCode');
}

/**
* Whether to hide the biller code from the end-user on the hosted checkout page
*
* @param bool $value
*/
public function setHideBillerCode($value)
{
return $this->setParameter('hideBillerCode', $value);
}

public function getHideCustomerReferenceNumber1()
{
return $this->getParameter('hideCustomerReferenceNumber1');
}

/**
* Whether to hide the customer configurable reference #1 from the end-user on the hosted checkout page
*
* @param bool $value
*/
public function setHideCustomerReferenceNumber1($value)
{
return $this->setParameter('hideCustomerReferenceNumber1', $value);
}

public function getHideCustomerReferenceNumber2()
{
return $this->getParameter('hideCustomerReferenceNumber2');
}

/**
* Whether to hide the customer configurable reference #2 from the end-user on the hosted checkout page
*
* @param bool $value
*/
public function setHideCustomerReferenceNumber2($value)
{
return $this->setParameter('hideCustomerReferenceNumber2', $value);
}

public function getHideCustomerReferenceNumber3()
{
return $this->getParameter('hideCustomerReferenceNumber3');
}

/**
* Whether to hide the customer configurable reference #3 from the end-user on the hosted checkout page
*
* @param bool $value
*/
public function setHideCustomerReferenceNumber3($value)
{
return $this->setParameter('hideCustomerReferenceNumber3', $value);
}

/**
* @deprecated Alias. Use standard `getCreateToken()` instead.
*/
public function getGenerateToken()
{
return $this->getParameter('generateToken');
return $this->getCreateToken();
}

/**
* Indicate whether or not to generate a token for the card used in the transaction
*
* @deprecated Alias. Use standard `setCreateToken()` instead.
*
* @param bool $value Generate a token or not
*/
public function setGenerateToken($value)
{
return $this->setParameter('generateToken', $value);
return $this->setCreateToken($value);
}

public function getCustomerNumber()
Expand All @@ -123,7 +213,7 @@ public function getCustomerNumber()
/**
* Set the unique customer ID in the merchant system
*
* @param bool $value Customer number to set
* @param string $value Customer number to set
*/
public function setCustomerNumber($value)
{
Expand All @@ -136,23 +226,34 @@ public function getData()

$amount = $this->getAmountInteger();
$data = array(
'HppParameters' => array(
'HideBillerCode' => (bool) $this->getHideBillerCode(),
'HideCrn1' => (bool) $this->getHideCustomerReferenceNumber1(),
'HideCrn2' => (bool) $this->getHideCustomerReferenceNumber2(),
'HideCrn3' => (bool) $this->getHideCustomerReferenceNumber3(),
),
'ProcessTxnData' => array(
'Action' => $amount > 0 ? 'payment' : 'verify_only',
'TestMode' => $this->getTestMode(),
'Amount' => $this->getAmountInteger(),
'BillerCode' => $this->getBillerCode(),
'Crn1' => $this->getCustomerReferenceNumber1(),
'Crn2' => $this->getCustomerReferenceNumber2(),
'Crn3' => $this->getCustomerReferenceNumber3(),
'Currency' => $this->getCurrency(),
// 1 - no; 3 - always (don't leave it up to system or customer)
'TokenisationMode' => $this->getGenerateToken() ? 3 : 1,
'TokenisationMode' => $this->getCreateToken() ? 3 : 1,
'MerchantReference' => $this->getTransactionId(),
'SubType' => 'single',
'Type' => 'internet',
),
'RedirectionUrl' => $this->getReturnUrl(),
'WebHookUrl' => $this->getNotifyUrl(),
);
if ($this->getCancelUrl()) {
$data['HppParameters']['ReturnBarLabel'] = 'Cancel';
$data['HppParameters']['ReturnBarUrl'] = $this->getCancelUrl();
}
// add item details if available
$items = $this->getItems();
if ($items) {
Expand Down Expand Up @@ -202,6 +303,14 @@ public function getData()
}
}

// add stored card token if available
if ($this->getToken() || $this->getCardReference()) {
$data['ProcessTxnData']['DVTokenData'] = array(
'DVToken' => $this->getToken() ?? $this->getCardReference(),
'UpdateDVTokenExpiryDate' => false,
);
}

return $data;
}

Expand Down
15 changes: 15 additions & 0 deletions tests/Message/CompletePurchaseResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public function testCompletePurchaseSuccess()
$this->assertSame('Approved', $this->response->getMessage());
$this->assertSame('372626', $this->response->getTransactionReference());
$this->assertSame('MC', $this->response->getCardType());
$this->assertNull($this->response->getCardReference());

// confirm the request format was valid
$requestData = $this->response->getRequest()->getData();
Expand Down Expand Up @@ -138,6 +139,7 @@ public function testCompletePurchaseFailure()
$this->assertSame('Invalid card number', $this->response->getMessage());
$this->assertNull($this->response->getTransactionReference());
$this->assertNull($this->response->getCardType());
$this->assertNull($this->response->getCardReference());

// confirm the request format was valid
$requestData = $this->response->getRequest()->getData();
Expand Down Expand Up @@ -165,9 +167,22 @@ public function testCompletePurchaseError()
$this->assertSame('Invalid credentials', $this->response->getMessage());
$this->assertNull($this->response->getTransactionReference());
$this->assertNull($this->response->getCardType());
$this->assertNull($this->response->getCardReference());

$data = $this->response->getData();

$this->assertSame(1, $data['ResponseCode']);
}

public function testCompletePurchaseReturnsCardReference()
{
// adjust to have a token
$this->responseData['DVToken'] = '1234567890123456';

$this->response = new CompletePurchaseResponse($this->getMockRequest(), $this->responseData);

$this->assertTrue($this->response->isSuccessful());
$this->assertFalse($this->response->isRedirect());
$this->assertSame('1234567890123456', $this->response->getCardReference());
}
}
Loading