Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/Endpoint.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Unicodeveloper\Paystack;
namespace Xeviant\LaravelPaystack;

class Endpoint
{
Expand Down
106 changes: 106 additions & 0 deletions src/Paystack.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,52 @@ public function makePaymentRequest($data = null)
return $this;
}

/**
* Charge a customer via reusable authorization on Paystack
* Included the option to pass the payload to this method for situations
* when the payload is built on the fly (not passed to the controller from a view).
*
* @param null $data
*
* @return array
*/
public function chargeAuthorization($data = null)
{
if ($data == null) {
$data = [
'authorization_code' => request()->authorization_code,
'amount' => intval(request()->amount),
'reference' => request()->reference,
'email' => request()->email,
'plan' => request()->plan,
'subaccount' => request()->subaccount,
'transaction_charge' => request()->transaction_charge,
'invoice_limit' => request()->invoice_limit,
/*
* to allow use of metadata on Paystack dashboard and a means to return additional data back to redirect url
* form need an input field: <input type="hidden" name="metadata" value="{{ json_encode($array) }}" >
*array must be set up as: $array = [ 'custom_fields' => [
* ['display_name' => "Cart Id", "variable_name" => "cart_id", "value" => "2"],
* ['display_name' => "Sex", "variable_name" => "sex", "value" => "female"],
* .
* .
* .
* ]
*
* ]
*/
'metadata' => request()->metadata,
];

// Remove the fields which were not sent (value would be null)
array_filter($data);
}

$this->response = $this->paystack->transactions()->charge($data);

return $this->getResponse();
}

/**
* Get the authorization url from the callback response.
*
Expand Down Expand Up @@ -139,6 +185,47 @@ public function getAuthorizationResponse($data)
return $this->getResponse();
}

/**
* Checks a authorization.
*
* @param array $data
*
* @return array|string
*/
public function checkAuthorization($data = null)
{
if ($data == null) {
$data = [
'authorization_code' => request()->authorization_code,
'amount' => intval(request()->amount),
'email' => request()->email,
'currency' => request()->currency,
];

// Remove the fields which were not sent (value would be null)
array_filter($data);
}

return $this->paystack->transactions()->checkAuthorization($data);
}

/**
* Deactivates an authorization.
*
* @param array $data
*
* @return array|string
*/
public function deactivateAuthorization(string $authcode)
{
$data = [
'authorization_code' => $authcode
];

return $this->paystack->customers()->deactivateAuthorization($data);
}


/**
* Hit Paystack Gateway to Verify that the transaction is valid.
*/
Expand Down Expand Up @@ -358,6 +445,25 @@ public function updateCustomer($customerId)
return $this->paystack->customers()->update($customerId, $data);
}

/**
* Refund a Transaction based on reference or id.
*
* @param $transaction
*
* @return array
*/
public function refundTransaction($transaction)
{
$data = [
'transaction' => $transaction,
'amount' => request()->amount,
'customer_note' => request()->customer_note,
'merchant_note' => request()->merchant_note,
];

return $this->paystack->refund()->create($data);
}

/**
* Export transactions in .CSV.
*
Expand Down
4 changes: 2 additions & 2 deletions tests/PaystackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* file that was distributed with this source code.
*/

namespace Unicodeveloper\Paystack\Test;
namespace Xeviant\LaravelPaystack\Test;

use Mockery as m;
use PHPUnit\Framework\TestCase;
Expand All @@ -22,7 +22,7 @@ class PaystackTest extends TestCase

public function setUp()
{
$this->paystack = m::mock('Unicodeveloper\Paystack\Paystack');
$this->paystack = m::mock('Xeviant\Paystack\Paystack');
$this->mock = m::mock('GuzzleHttp\Client');
}

Expand Down