Skip to content

Commit 824286b

Browse files
committed
Major Feature Release: Paystack Transaction Resource
0 parents  commit 824286b

File tree

12 files changed

+1510
-0
lines changed

12 files changed

+1510
-0
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
composer.phar
2+
/vendor/
3+
4+
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
5+
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
6+
# composer.lock
7+
8+
/.idea

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# matscode/paystack
2+
This package is for communicating with PAYSTACK RESTful API
3+
4+
## Requirements
5+
- Curl
6+
7+
## Install
8+
9+
### Via Composer
10+
11+
``` bash
12+
$ composer require matscode/paystack
13+
```

composer.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "matscode/paystack",
3+
"description": "This package is for communicating with PAYSTACK API",
4+
"type": "library",
5+
"keywords": ["payment","paystack", "php"],
6+
"license": "GNU GPLv3",
7+
"minimum-stability": "stable",
8+
"autoload": {
9+
"psr-4": {"Matscode\\Paystack\\": "src/"}
10+
},
11+
"authors": [
12+
{
13+
"name": "Michael Akanji",
14+
"email": "matscode@gmail.com",
15+
"homepage": "http://michaelakanji.com"
16+
}
17+
],
18+
"require": {}
19+
}

src/Base.php

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
/**
3+
*
4+
* Description
5+
*
6+
* @package Paystack
7+
* @category Source
8+
* @author Michael Akanji <matscode@gmail.com>
9+
* @date 2017-06-26
10+
* @copyright (c) 2016 - 2017, TECRUM (http://www.tecrum.com)
11+
*
12+
*/
13+
14+
namespace Matscode\Paystack;
15+
16+
use Matscode\Paystack\CURL;
17+
use Matscode\Paystack\Utility\Text;
18+
19+
class Base
20+
{
21+
22+
private
23+
$_apiBaseUrl = 'https://api.paystack.co/',
24+
$_curl,
25+
$_secretKey,
26+
$_endPoint;
27+
28+
public
29+
$resource,
30+
$action,
31+
$args,
32+
$data,
33+
// response from the endpoint
34+
$response;
35+
36+
public function __construct( $secretKey )
37+
{
38+
// save key in memory
39+
$this->_secretKey = $secretKey;
40+
41+
return $this;
42+
}
43+
44+
public function setResource( $resource )
45+
{
46+
$this->resource = $resource;
47+
48+
return $this;
49+
}
50+
51+
public function setAction( $action, array $args = [] )
52+
{
53+
if ( ! is_array( $args ) ) {
54+
throw new \Exception( 'Action arguments can only be of datatype Array' );
55+
}
56+
57+
$this->action = $action;
58+
$this->args = $args;
59+
60+
return $this;
61+
}
62+
63+
/**
64+
* Initiate Request to the paystack RESTful API and return response Obj
65+
*
66+
* @param array $withData
67+
* @param string $requestMethod
68+
* @param bool $returnArray set to true to return response as associate array
69+
*
70+
* @todo Utilize the third argument..
71+
*
72+
* @return mixed
73+
* @throws \Exception
74+
*/
75+
public function sendRequest( array $withData = [], $requestMethod = 'POST', $returnArray = false )
76+
{
77+
if ( ! is_array( $withData ) ) {
78+
throw new \Exception( 'sendRequest arguments can only be of datatype Array' );
79+
}
80+
81+
$this->data = $withData;
82+
83+
$this->_endPoint = $this->_apiBaseUrl .
84+
Text::removeSlashes( $this->resource ) . '/' .
85+
Text::removeSlashes( $this->action );
86+
// append parameters to endPoint
87+
if ( count( $this->args ) > 0 ) {
88+
$this->_endPoint .= '/' . implode( '/', $this->args );
89+
}
90+
91+
// send the request and return result as json object
92+
$this->_curl =
93+
( new CURL(
94+
$this->_endPoint,
95+
$requestMethod ) )
96+
->setRequestHeader( 'Authorization', 'Bearer ' . $this->_secretKey );
97+
98+
$this->response =
99+
json_decode(
100+
$this->_curl
101+
->run( $this->data, 'json' ) );
102+
103+
return $this->response;
104+
}
105+
106+
/**
107+
* @return mixed
108+
*/
109+
public function getEndPoint()
110+
{
111+
// this works only after executing sendRequest
112+
return $this->_endPoint;
113+
}
114+
115+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy