Skip to content

Commit

Permalink
Merge pull request #6 from njzw/main
Browse files Browse the repository at this point in the history
Version 2 Upgrade
  • Loading branch information
contitouchtechnologies authored Apr 30, 2024
2 parents bb92bed + 0ec2ad6 commit 7b884a3
Show file tree
Hide file tree
Showing 7 changed files with 530 additions and 69 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ basic-redirect.php
basic-direct.php
redirect.php
direct.php
.env
disburse.php
ssl.php
.env
files
130 changes: 67 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,51 @@

2. ContiPay Secret and Key

## API URL

```markdown
UAT_URL = https://api2-test.contipay.co.zw
LIVE_URL = https://api-v2.contipay.co.zw
```

## How it Works

### 1. Install latest with Composer

```bash
composer require nigel/contipay-php:^1.0.6
composer require nigel/contipay-php
```

### 2. Require Autoload File and Create an Instance of Contipay
### 2. Require Autoload File and Classes Imports

```php
<?php
use Contipay\Core\Contipay;
use Contipay\Helpers\DirectMethod;
use Contipay\Helpers\RedirectMethod;
use Contipay\Helpers\SimpleDirectMethod;
use Contipay\Helpers\SimpleRedirectMethod;
use Contipay\Helpers\Payload\PayloadGenerator;

require_once __DIR__ . '/vendor/autoload.php';
```

### 3. Process Payment

#### i. Basic Direct Payment Example
$webhookUrl = "https://www.contipay.co.zw/api/webhook";
$successUrl = "https://www.contipay.co.zw/api/success";
$cancelUrl = "https://www.contipay.co.zw/api/cancel";
$merchantCode = 00;
$phone = "2637****340";
$amount = (float) 10;

```php
$contipay = new Contipay(
'token-here', // copy from .env or paste directly
'secret-here', // copy from .env or paste directly
);
```

$phone = "263782000340";
### 3. Process Payment

#### i. Basic Direct Payment Example

```php

$payload = (new SimpleDirectMethod($merchantCode, $webhookUrl))
->setUpProvider('InnBucks', 'IB')
->preparePayload(
$amount,
$phone,
$payload = (new PayloadGenerator($merchantCode, $webhookUrl))
->setUpProviders('InnBucks', 'IB')
->simpleDirectPayload(
$amount,
$phone,
);

$res = $contipay
->setAppMode("DEV") // LIVE as another option
$res = $contipay->setAppMode("DEV")
->setPaymentMethod()
->process($payload);

Expand All @@ -66,25 +62,21 @@ echo $res;
#### ii. Basic Redirect Payment Example

```php
$contipay = new Contipay(
'token-here', // copy from .env or paste directly
'secret-here', // copy from .env or paste directly
);

$phone = "263782000340";

$payload = (
new SimpleRedirectMethod(
new PayloadGenerator(
$merchantCode,
$webhookUrl,
$successUrl,
$cancelUrl,
$cancelUrl
)
)->preparePayload($amount, $phone);
)->simpleRedirectPayload(
$amount,
$phone
);

$res = $contipay
->setAppMode("DEV") // LIVE as another option
->setPaymentMethod("redirect")
$res = $contipay->setAppMode("DEV")
->setPaymentMethod('redirect')
->process($payload);

header('Content-type: application/json');
Expand All @@ -95,35 +87,23 @@ echo $res;
#### iii. Direct Payment Example

```php
$contipay = new Contipay(
'token-here', // copy from .env or paste directly
'secret-here', // copy from .env or paste directly
);

$phone = "263782000340";

$payload = (
new DirectMethod(
new PayloadGenerator(
$merchantCode,
$webhookUrl
)
)->setUpCustomer('Nigel', 'Jaure', $phone, 'ZW', 'nigeljaure@gmail.com')
->setUpProviders('Ecocash', 'EC')
->setUpAccountDetails($phone, 'Nigel Jaure')
->setUpTransaction($amount, "USD")
->preparePayload();
->directPayload();

$res = $contipay
->setAppMode("DEV")
->setPaymentMethod()
->process($payload);


$res = $contipay
->setAppMode("DEV") // LIVE as another option
->setPaymentMethod()
->process($payload);

header('Content-type: application/json');

echo $res;
Expand All @@ -132,29 +112,51 @@ echo $res;
#### iv. Redirect Payment Example

```php
$contipay = new Contipay(
'token-here', // copy from .env or paste directly
'secret-here', // copy from .env or paste directly
);

$phone = "263782000340";

$payload = (
new RedirectMethod(
new PayloadGenerator(
$merchantCode,
$webhookUrl,
$successUrl,
$cancelUrl
)
)->setUpCustomer('Nigel', 'Jaure', $phone, 'ZW', 'nigeljaure@gmail.com')
->setUpTransaction($amount, "USD")
->preparePayload();
->redirectPayload();

$res = $contipay->setAppMode("DEV")
->setPaymentMethod('redirect')
->process($payload);

header('Content-type: application/json');

echo $res;;
```

### 4. Disburse Payment

```php

$privateKey = <<<EOD
-----BEGIN PRIVATE KEY-----
YOUR KEY HERE
-----END PRIVATE KEY-----
EOD;

$payload = (
new PayloadGenerator(
$merchantCode,
$webhookUrl
)
)->setUpCustomer('Nigel', 'Jaure', $phone, 'ZW', 'nigeljaure@gmail.com')
->setUpProviders('Transfer', 'TF')
->setUpAccountDetails($phone, 'Nigel Jaure')
->setUpTransaction($amount, "USD")
->directPayload();

$res = $contipay
->setAppMode("DEV") // LIVE as another option
->setPaymentMethod("redirect")
->process($payload);
->setAppMode("DEV")
->setPaymentMethod()
->disburse($payload, $privateKey);

header('Content-type: application/json');

Expand Down Expand Up @@ -188,3 +190,5 @@ echo $res;
- Ensure to set the appropriate mode (`DEV` or `LIVE`) using the `setAppMode` method before processing payments.

- The provided examples cover basic scenarios, including direct and redirect payment methods, customer information setup, and transaction details.

- ContiPay JavaScript Alternative [here](https://github.com/njzw/contipay-js-client)
20 changes: 16 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0.6",
"version": "2.0.2",
"name": "nigel/contipay-php",
"description": "Contipay PHP Client",
"type": "library",
Expand All @@ -15,12 +15,24 @@
{
"name": "Nigel Jaure",
"email": "nigel.jaure@contitouch.co.zw",
"role": "Developer"
"role": "Developer",
"homepage": "https://github.com/njzw"
},
{
"name": "ContiTouch Technologies",
"homepage": "https://contitouch.co.zw",
"role": "Owner"
},
{
"name": "ContiPay",
"homepage": "https://contipay.co.zw",
"role": "Owner"
}
],
"minimum-stability": "stable",
"prefer-stable": true,
"require": {
"guzzlehttp/guzzle": "^7.0"
"guzzlehttp/guzzle": "^7.0",
"nigel/utils": "^1.0"
}
}
}
39 changes: 38 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7b884a3

Please sign in to comment.