Skip to content

Commit

Permalink
Merge pull request #10 from AminulBD/future
Browse files Browse the repository at this point in the history
Upgraded the APIZ version to 4
  • Loading branch information
Shipu committed Apr 5, 2021
2 parents 66f9efb + 4b8574c commit f534abf
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 32 deletions.
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
"type": "library",
"require": {
"php": ">=5.6",
"nahid/apiz": "3.0.*"
"nahid/apiz": "4.*"
},
"license": "MIT",
"authors": [
{
"name": "Shipu Ahamed",
"email": "shipuahamed01@gmail.com"
},
{
"name": "Aminul Islam",
"email": "me@aminul.net"
}
],
"autoload": {
Expand Down
39 changes: 34 additions & 5 deletions src/Apis/BaseApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/**
* Class BaseApi
*
* @package Shipu\Bkash\Apis
*/
abstract class BaseApi extends AbstractApi
Expand All @@ -28,19 +29,27 @@ abstract class BaseApi extends AbstractApi
protected $response = BkashResponse::class;

/**
* @var
* @var array
*/
protected $config;

/**
* @var array
*/
protected $options = [
'timeout' => 30
'timeout' => 30,
];

/**
* @var bool
*/
protected $authorization = false;

/**
* @var string
*/
protected $prefix;

/**
* BaseApi constructor.
*
Expand All @@ -49,8 +58,8 @@ abstract class BaseApi extends AbstractApi
public function __construct( $config )
{
$this->subDomain = $this->subDomain();
$this->env = $config[ BkashKey::SANDBOX ] ? 'sandbox' : 'pay';
$this->prefix = '/' . $config[ BkashKey::VERSION ] . $this->urlPrefix();
$this->env = $config[BkashKey::SANDBOX] ? 'sandbox' : 'pay';
$this->prefix = '/' . $config[BkashKey::VERSION] . $this->urlPrefix();
$this->config = $config;

parent::__construct();
Expand Down Expand Up @@ -78,14 +87,34 @@ public function baseUrl()
return "https://" . $api . ".bka.sh";
}

/**
* Get the base URL for the guzzle client.
*
* @return string
*/
public function getBaseURL()
{
return $this->baseUrl();
}

/**
* Get the prefix for guzzle client.
*
* @return string
*/
public function getPrefix()
{
return $this->prefix;
}

/**
* @param $token
*
* @return AbstractApi|bool
*/
public function authorization( $token )
{
return $this->headers([
return $this->withHeaders([
'Authorization' => $token,
'X-APP-Key' => $this->config[ BkashKey::APP_KEY ]
]);
Expand Down
2 changes: 1 addition & 1 deletion src/Apis/Checkout/PaymentApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class PaymentApi extends CheckoutBaseApi
*/
public function create( $amount, $merchantInvoiceNumber, $intent = 'sale', $currency = 'BDT', $merchantAssociationInfo = null )
{
return $this->json([
return $this->withJson([
'amount' => $amount,
'merchantInvoiceNumber' => $merchantInvoiceNumber,
'intent' => $intent,
Expand Down
2 changes: 1 addition & 1 deletion src/Apis/Checkout/PayoutApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PayoutApi extends CheckoutBaseApi
*/
public function b2cPayment( $amount, $merchantInvoiceNumber, $receiverMSISDN, $currency = 'BDT' )
{
return $this->json([
return $this->withJson([
'amount' => $amount,
'merchantInvoiceNumber' => $merchantInvoiceNumber,
'receiverMSISDN' => $receiverMSISDN,
Expand Down
8 changes: 4 additions & 4 deletions src/Apis/Checkout/SupportApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function queryOrganizationBalance()
*/
public function intraAccountTransfer( $amount, $transferType, $currency = 'BDT' )
{
return $this->json([
return $this->withJson([
'amount' => $amount,
'currency' => $currency,
'transferType' => $transferType
Expand All @@ -41,7 +41,7 @@ public function intraAccountTransfer( $amount, $transferType, $currency = 'BDT'
*/
public function searchTransaction( $trxId )
{
return $this->get('/payment/search/' . $trxId);
return $this->withJson('/payment/search/' . $trxId);
}

/**
Expand All @@ -55,7 +55,7 @@ public function searchTransaction( $trxId )
*/
public function refundTransaction( $amount, $paymentID, $trxID, $reason, $sku )
{
return $this->json([
return $this->withJson([
'amount' => $amount,
'paymentID' => $paymentID,
'trxID' => $trxID,
Expand All @@ -72,7 +72,7 @@ public function refundTransaction( $amount, $paymentID, $trxID, $reason, $sku )
*/
public function refundStatus( $paymentID, $trxID )
{
return $this->json([
return $this->withJson([
'paymentID' => $paymentID,
'trxID' => $trxID
])->post('/payment/refund');
Expand Down
2 changes: 1 addition & 1 deletion src/Apis/Payment/CheckoutApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CheckoutApi extends PaymentBaseApi
*/
public function create( $amount, $merchantInvoiceNumber, $intent = 'sale', $currency = 'BDT' )
{
return $this->json([
return $this->withJson([
'amount' => $amount,
'merchantInvoiceNumber' => $merchantInvoiceNumber,
'intent' => $intent,
Expand Down
2 changes: 1 addition & 1 deletion src/Apis/Payment/DirectApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DirectApi extends PaymentBaseApi
*/
public function saleOrAuthorize( $mandateId, $amount, $merchantInvoiceNumber, $payerReferenceNumber, $intent = 'sale', $currency = 'BDT' )
{
return $this->json([
return $this->withJson([
'amount' => $amount,
'payerReferenceNumber' => $payerReferenceNumber,
'merchantInvoiceNumber' => $merchantInvoiceNumber,
Expand Down
2 changes: 1 addition & 1 deletion src/Apis/Payment/MandateApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class MandateApi extends PaymentBaseApi
*/
public function create( $firstPaymentDate, $frequency, $payerReferenceNumber, $requestType, $startRangeOfDays = null, $endRangeOfDays = null, $expiryDate = null, $amount = null, $merchantInvoiceNumber = null, $intent = 'sale', $currency = 'BDT' )
{
return $this->json([
return $this->withJson([
'firstPaymentDate' => $firstPaymentDate,
'frequency' => $frequency,
'payerReferenceNumber' => $payerReferenceNumber,
Expand Down
2 changes: 1 addition & 1 deletion src/Apis/Payment/PayoutApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PayoutApi extends PaymentBaseApi
*/
public function b2cPayment( $amount, $merchantInvoiceNumber, $receiverMSISDN, $currency = 'BDT' )
{
return $this->json([
return $this->withJson([
'amount' => $amount,
'merchantInvoiceNumber' => $merchantInvoiceNumber,
'receiverMSISDN' => $receiverMSISDN,
Expand Down
4 changes: 2 additions & 2 deletions src/Apis/Payment/SupportApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function queryOrganizationBalance()
*/
public function intraAccountTransfer( $amount, $transferType, $currency = 'BDT' )
{
return $this->json([
return $this->withJson([
'amount' => $amount,
'currency' => $currency,
'transferType' => $transferType
Expand All @@ -53,7 +53,7 @@ public function searchTransaction( $trxId )
*/
public function refund( $trxId, $amount, $currency = 'BDT' )
{
return $this->json([
return $this->withJson([
'amount' => $amount,
'currency' => $currency
])->post('/payment/refund/' . $trxId);
Expand Down
8 changes: 4 additions & 4 deletions src/Apis/Tokenized/AgreementApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AgreementApi extends TokenizedBaseApi
*/
public function create( $payerReference, $callbackUrl = null )
{
return $this->json([
return $this->withJson([
'payerReference' => $payerReference,
'callbackURL' => is_null($callbackUrl) ? $this->config [ BkashKey::CALL_BACK_URL ] : $callbackUrl
])->post('/agreement/create');
Expand All @@ -31,7 +31,7 @@ public function create( $payerReference, $callbackUrl = null )
*/
public function execute( $paymentId )
{
return $this->json([
return $this->withJson([
'paymentID' => $paymentId,
])->post('/agreement/execute');
}
Expand All @@ -43,7 +43,7 @@ public function execute( $paymentId )
*/
public function status( $agreementId )
{
return $this->json([
return $this->withJson([
'agreementID' => $agreementId,
])->post('/agreement/status');
}
Expand All @@ -55,7 +55,7 @@ public function status( $agreementId )
*/
public function cancel( $agreementId )
{
return $this->json([
return $this->withJson([
'agreementID' => $agreementId,
])->post('/agreement/cancel');
}
Expand Down
4 changes: 2 additions & 2 deletions src/Apis/Tokenized/CheckoutApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CheckoutApi extends TokenizedBaseApi
*/
public function create( $mode, $callbackUrl = null, $payerReference = null, $agreementId = null, $amount = null, $merchantInvoiceNumber = null, $currency = 'BDT', $intent = null )
{
return $this->json([
return $this->withJson([
'mode' => $mode,
'callbackURL' => is_null($callbackUrl) ? $this->config [ BkashKey::CALL_BACK_URL ] : $callbackUrl,
'payerReference' => $payerReference,
Expand All @@ -43,7 +43,7 @@ public function create( $mode, $callbackUrl = null, $payerReference = null, $agr
*/
public function execute( $paymentId )
{
return $this->json([
return $this->withJson([
'paymentID' => $paymentId,
])->post('/execute');
}
Expand Down
6 changes: 3 additions & 3 deletions src/Apis/Tokenized/PaymentApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PaymentApi extends TokenizedBaseApi
*/
public function create( $agreementId, $amount, $merchantInvoiceNumber, $callbackUrl = null, $intent = 'sale', $currency = 'BDT' )
{
return $this->json([
return $this->withJson([
'agreementID' => $agreementId,
'amount' => $amount,
'merchantInvoiceNumber' => $merchantInvoiceNumber,
Expand All @@ -39,7 +39,7 @@ public function create( $agreementId, $amount, $merchantInvoiceNumber, $callback
*/
public function execute( $paymentId )
{
return $this->json([
return $this->withJson([
'paymentID' => $paymentId,
])->post('/payment/execute');
}
Expand All @@ -51,7 +51,7 @@ public function execute( $paymentId )
*/
public function status( $paymentId )
{
return $this->json([
return $this->withJson([
'paymentID' => $paymentId,
])->post('/payment/status');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Apis/Tokenized/SupportApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SupportApi extends TokenizedBaseApi
*/
public function searchTransaction( $trxId )
{
return $this->json([
return $this->withJson([
'trxID' => $trxId,
])->post('/general/searchTransaction');
}
Expand Down
8 changes: 4 additions & 4 deletions src/Traits/TokenableApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ trait TokenableApi
*/
public function grantToken()
{
$tokenResponse = $this->json([
$tokenResponse = $this->withJson([
'app_key' => $this->config [ BkashKey::APP_KEY ],
'app_secret' => $this->config [ BkashKey::APP_SECRET ],
])->headers([
])->withHeaders([
'username' => $this->config [ BkashKey::USER_NAME ],
'password' => $this->config [ BkashKey::PASSWORD ],
])->post('/token/grant');
Expand All @@ -33,11 +33,11 @@ public function grantToken()
*/
public function refreshToken( $refreshToken )
{
$refreshTokenResponse = $this->json([
$refreshTokenResponse = $this->withJson([
'app_key' => $this->config [ BkashKey::APP_KEY ],
'app_secret' => $this->config [ BkashKey::APP_SECRET ],
'refresh_token' => $refreshToken,
])->headers([
])->withHeaders([
'username' => $this->config [ BkashKey::USER_NAME ],
'password' => $this->config [ BkashKey::PASSWORD ],
])->post('/token/grant');
Expand Down

0 comments on commit f534abf

Please sign in to comment.