Skip to content

Pass $transaction_id to verify transaction #166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 21, 2022
Merged
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
53 changes: 26 additions & 27 deletions src/Paystack.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function setKey()
*/
private function setRequestOptions()
{
$authBearer = 'Bearer '. $this->secretKey;
$authBearer = 'Bearer ' . $this->secretKey;

$this->client = new Client(
[
Expand All @@ -101,7 +101,7 @@ private function setRequestOptions()
}


/**
/**

* Initiate a payment request to Paystack
* Included the option to pass the payload to this method for situations
Expand All @@ -111,7 +111,7 @@ private function setRequestOptions()

public function makePaymentRequest($data = null)
{
if ( $data == null ) {
if ($data == null) {

$quantity = intval(request()->quantity ?? 1);

Expand Down Expand Up @@ -214,7 +214,7 @@ public function getAuthorizationUrl($data = null)
return $this;
}

/**
/**
* Get the authorization callback response
* In situations where Laravel serves as an backend for a detached UI, the api cannot redirect
* and might need to take different actions based on the success or not of the transaction
Expand All @@ -232,9 +232,9 @@ public function getAuthorizationResponse($data)
/**
* Hit Paystack Gateway to Verify that the transaction is valid
*/
private function verifyTransactionAtGateway()
private function verifyTransactionAtGateway($transaction_id = null)
{
$transactionRef = request()->query('trxref');
$transactionRef = $transaction_id ?? request()->query('trxref');

$relativeUrl = "/transaction/verify/{$transactionRef}";

Expand All @@ -245,9 +245,9 @@ private function verifyTransactionAtGateway()
* True or false condition whether the transaction is verified
* @return boolean
*/
public function isTransactionVerificationValid()
public function isTransactionVerificationValid($transaction_id = null)
{
$this->verifyTransactionAtGateway();
$this->verifyTransactionAtGateway($transaction_id);

$result = $this->getResponse()['message'];

Expand Down Expand Up @@ -375,7 +375,6 @@ public function createPlan()
$this->setRequestOptions();

return $this->setHttpResponse("/plan", 'POST', $data)->getResponse();

}

/**
Expand Down Expand Up @@ -436,7 +435,7 @@ public function createCustomer()
public function fetchCustomer($customer_id)
{
$this->setRequestOptions();
return $this->setHttpResponse('/customer/'. $customer_id, 'GET', [])->getResponse();
return $this->setHttpResponse('/customer/' . $customer_id, 'GET', [])->getResponse();
}

/**
Expand All @@ -456,7 +455,7 @@ public function updateCustomer($customer_id)
];

$this->setRequestOptions();
return $this->setHttpResponse('/customer/'. $customer_id, 'PUT', $data)->getResponse();
return $this->setHttpResponse('/customer/' . $customer_id, 'PUT', $data)->getResponse();
}

/**
Expand Down Expand Up @@ -566,7 +565,7 @@ public function disableSubscription()
public function fetchSubscription($subscription_id)
{
$this->setRequestOptions();
return $this->setHttpResponse('/subscription/'.$subscription_id, 'GET', [])->getResponse();
return $this->setHttpResponse('/subscription/' . $subscription_id, 'GET', [])->getResponse();
}

/**
Expand Down Expand Up @@ -602,7 +601,7 @@ public function getAllPages()
public function fetchPage($page_id)
{
$this->setRequestOptions();
return $this->setHttpResponse('/page/'.$page_id, 'GET', [])->getResponse();
return $this->setHttpResponse('/page/' . $page_id, 'GET', [])->getResponse();
}

/**
Expand All @@ -619,16 +618,17 @@ public function updatePage($page_id)
];

$this->setRequestOptions();
return $this->setHttpResponse('/page/'.$page_id, 'PUT', $data)->getResponse();
return $this->setHttpResponse('/page/' . $page_id, 'PUT', $data)->getResponse();
}

/**
/**
* Creates a subaccount to be used for split payments . Required params are business_name , settlement_bank , account_number , percentage_charge
*
* @return array
*/

public function createSubAccount(){
public function createSubAccount()
{
$data = [
"business_name" => request()->business_name,
"settlement_bank" => request()->settlement_bank,
Expand All @@ -643,31 +643,30 @@ public function createSubAccount(){

$this->setRequestOptions();
return $this->setHttpResponse('/subaccount', 'POST', array_filter($data))->getResponse();

}

/**
/**
* Fetches details of a subaccount
* @param subaccount code
* @return array
*/
public function fetchSubAccount($subaccount_code){
public function fetchSubAccount($subaccount_code)
{

$this->setRequestOptions();
return $this->setHttpResponse("/subaccount/{$subaccount_code}","GET",[])->getResponse();

return $this->setHttpResponse("/subaccount/{$subaccount_code}", "GET", [])->getResponse();
}

/**
/**
* Lists all the subaccounts associated with the account
* @param $per_page - Specifies how many records to retrieve per page , $page - SPecifies exactly what page to retrieve
* @return array
*/
public function listSubAccounts($per_page,$page){
public function listSubAccounts($per_page, $page)
{

$this->setRequestOptions();
return $this->setHttpResponse("/subaccount/?perPage=".(int) $per_page."&page=".(int) $page,"GET")->getResponse();

return $this->setHttpResponse("/subaccount/?perPage=" . (int) $per_page . "&page=" . (int) $page, "GET")->getResponse();
}


Expand All @@ -677,7 +676,8 @@ public function listSubAccounts($per_page,$page){
* @return array
*/

public function updateSubAccount($subaccount_code){
public function updateSubAccount($subaccount_code)
{
$data = [
"business_name" => request()->business_name,
"settlement_bank" => request()->settlement_bank,
Expand All @@ -693,6 +693,5 @@ public function updateSubAccount($subaccount_code){

$this->setRequestOptions();
return $this->setHttpResponse("/subaccount/{$subaccount_code}", "PUT", array_filter($data))->getResponse();

}
}