Skip to content

Commit

Permalink
Merge pull request #261 from blockchyp/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
devops-blockchyp committed Apr 3, 2024
1 parent 5b7a365 commit 83c2e06
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 2 deletions.
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4690,6 +4690,54 @@ echo 'Response: ' . print_r($response, true) . PHP_EOL;

```

#### Merchant Credential Generation



* **API Credential Types:** Partner
* **Required Role:** Partner API Access

This API allows partners to generate API credentials for a merchant.

The `merchantId` is required and must be the id of a valid merchant.

Credentials are not delete protected by default. Pass in `deleteProtected` to enable delete protection.

The optional `notes` field will populate the notes in the credentials.

By default no roles will be assigned unless valid, comma-delimited, role codes are passed in the `roles` field.




```php
<?php

// For composer based systems
require_once('vendor/autoload.php');

// For manual installation
#require_once('/path/to/blockchyp/init.php');

use BlockChyp\BlockChyp;

BlockChyp::setApiKey(getenv('BC_API_KEY'));
BlockChyp::setBearerToken(getenv('BC_BEARER_TOKEN'));
BlockChyp::setSigningKey(getenv('BC_SIGNING_KEY'));

// Populate request values
$request = [
];


$response = BlockChyp::merchantCredentialGeneration($request);


// View the result
echo 'Response: ' . print_r($response, true) . PHP_EOL;

```




Expand Down
24 changes: 24 additions & 0 deletions examples/MerchantCredentialGenerationExample.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

// For composer based systems
require_once('vendor/autoload.php');

// For manual installation
#require_once('/path/to/blockchyp/init.php');

use BlockChyp\BlockChyp;

BlockChyp::setApiKey(getenv('BC_API_KEY'));
BlockChyp::setBearerToken(getenv('BC_BEARER_TOKEN'));
BlockChyp::setSigningKey(getenv('BC_SIGNING_KEY'));

// Populate request values
$request = [
];


$response = BlockChyp::merchantCredentialGeneration($request);


// View the result
echo 'Response: ' . print_r($response, true) . PHP_EOL;
13 changes: 13 additions & 0 deletions lib/BlockChyp.php
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,19 @@ public static function partnerCommissionBreakdown($request)
{
return self::gatewayRequest('POST', '/api/partner-commission-breakdown', $request);
}
/**
* Generates and returns api credentials for a given merchant.
*
* @param array $request The request body.
*
* @throws \BlockChyp\Exception\ConnectionException if the connection fails.
*
* @return array The API response.
*/
public static function merchantCredentialGeneration($request)
{
return self::gatewayRequest('POST', '/api/creds/generateMerchant', $request);
}
/**
* Returns profile information for a merchant.
*
Expand Down
7 changes: 5 additions & 2 deletions lib/Exception/BlockChypException.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ public static function factory($message, $httpStatus = null, $httpBody = null)
$instance = new static($message);
$instance->setHttpStatus($httpStatus);
$instance->setHttpBody($httpBody);
$instance->setJsonBody(json_decode($httpBody, true));

if (isset($httpBody)) {
$httpBody = json_decode($httpBody, true);
}
$instance->setJsonBody($httpBody);

return $instance;
}

Expand Down
50 changes: 50 additions & 0 deletions tests/itests/MerchantCredentialGenerationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

use BlockChyp\BlockChyp;

require_once(__DIR__ . '/../BlockChypTestCase.php');

class MerchantCredentialGenerationTest extends BlockChypTestCase
{

/**
* @group itest
*/
public function testMerchantCredentialGeneration()
{
$config = $this->loadTestConfiguration();

BlockChyp::setApiKey($config->apiKey);
BlockChyp::setBearerToken($config->bearerToken);
BlockChyp::setSigningKey($config->signingKey);
BlockChyp::setGatewayHost($config->gatewayHost);
BlockChyp::setTestGatewayHost($config->testGatewayHost);
BlockChyp::setDashboardHost($config->dashboardHost);

echo 'Running MerchantCredentialGenerationTest...' . PHP_EOL; // Set request values
$request = [
'test' => true,
'merchantId' => '<MERCHANT ID>',
];

// self::logRequest($request);

try {

$response = BlockChyp::merchantCredentialGeneration($request);

// self::logResponse($response);

// Response assertions

$this->assertTrue($response['success']);

} catch (Exception $ex) {

echo $ex->getTraceAsString();
$this->assertEmpty($ex);

}
$this->processResponseDelay($request);
}
}
46 changes: 46 additions & 0 deletions tests/itests/Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

use BlockChyp\BlockChyp;

require_once(__DIR__ . '/../BlockChypTestCase.php');

class Test extends BlockChypTestCase
{

/**
* @group itest
*/
public function test()
{
$config = $this->loadTestConfiguration();

BlockChyp::setApiKey($config->apiKey);
BlockChyp::setBearerToken($config->bearerToken);
BlockChyp::setSigningKey($config->signingKey);
BlockChyp::setGatewayHost($config->gatewayHost);
BlockChyp::setTestGatewayHost($config->testGatewayHost);
BlockChyp::setDashboardHost($config->dashboardHost);

echo 'Running Test...' . PHP_EOL; // Set request values
$request = [
];

// self::logRequest($request);

try {

$response = BlockChyp::merchantCredentialGeneration($request);

// self::logResponse($response);

// Response assertions

} catch (Exception $ex) {

echo $ex->getTraceAsString();
$this->assertEmpty($ex);

}
$this->processResponseDelay($request);
}
}

0 comments on commit 83c2e06

Please sign in to comment.