Skip to content

Commit df370a3

Browse files
authored
Revise README for TypeScript client integration
Updated README to reflect TypeScript client usage and examples.
1 parent 465cd41 commit df370a3

1 file changed

Lines changed: 34 additions & 34 deletions

File tree

README.md

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# Flexpay Typescript
22

3-
![Lint](https://github.com/devscast/flexpay/actions/workflows/lint.yaml/badge.svg)
4-
![Test](https://github.com/devscast/flexpay/actions/workflows/test.yaml/badge.svg)
5-
[![Latest Stable Version](https://poser.pugx.org/devscast/flexpay/version)](https://packagist.org/packages/devscast/flexpay)
6-
[![Total Downloads](https://poser.pugx.org/devscast/flexpay/downloads)](https://packagist.org/packages/devscast/flexpay)
7-
[![License](https://poser.pugx.org/devscast/flexpay/license)](https://packagist.org/packages/devscast/flexpay)
3+
![npm](https://img.shields.io/npm/v/@devscast/flexpay?style=flat-square)
4+
![npm](https://img.shields.io/npm/dt/@devscast/flexpay?style=flat-square)
5+
[![Lint](https://github.com/devscast/flexpay-ts/actions/workflows/lint.yml/badge.svg?branch=main)](https://github.com/devscast/flexpay-ts/actions/workflows/lint.yml)
6+
[![Tests](https://github.com/devscast/flexpay-ts/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/devscast/flexpay-ts/actions/workflows/test.yml)
7+
![GitHub](https://img.shields.io/github/license/devscast/flexpay-ts?style=flat-square)
88

99
For privacy reasons, Flexpay original documentation cannot be shared without written permission, for more information about credentials
1010
and implementation details, please reach them at flexpay.cd
1111

1212
## Installation
13-
You can use the PHP client by installing the Composer package and adding it to your application’s dependencies:
13+
You can use the Typescript client by installing the npm package and adding it to your application’s dependencies:
1414

1515
```bash
16-
composer require devscast/flexpay
16+
npm install @devscast/flexpay
1717
```
1818
## Usage
1919

@@ -24,41 +24,34 @@ composer require devscast/flexpay
2424

2525
Then use these credentials to authenticate your client
2626

27-
```php
28-
use Devscast\Flexpay\Client as Flexpay;
29-
use Devscast\Flexpay\Credential;
30-
use Devscast\Flexpay\Environment;
31-
32-
$flexpay = new Flexpay(
33-
new Credential('token', 'merchant_code'),
34-
Environment::SANDBOX // use Environment::LIVE for production
35-
);
27+
```ts
28+
import { Client as Flexpay } from "@devscast/flexpay";
29+
30+
const flexpay = new Flexpay("merchant_code", "token", "dev") // use "prod" for production
3631
```
3732

3833
### Create a Payment Request
3934

40-
```php
41-
use Devscast\Flexpay\Data\Currency;
42-
use Devscast\Flexpay\Request\CardRequest;
43-
use Devscast\Flexpay\Request\MobileRequest;
35+
```typescript
36+
import { CardRequest, MobileRequest } from "@devscast/flexpay";
4437

45-
$mobile = new MobileRequest(
38+
const mobile = {
4639
amount: 10, // 10 USD
47-
currency: Currency::USD,
40+
currency: "USD",
4841
phone: "243999999999",
4942
reference: "your_unique_transaction_reference",
5043
description: "your_transaction_description",
5144
callbackUrl: "your_website_webhook_url",
52-
);
45+
} as MobileRequest;
5346

54-
$card = new CardRequest(
47+
const card = {
5548
amount: 10, // 10 USD
5649
currency: Currency::USD,
5750
reference: "your_unique_transaction_reference",
5851
description: "your_transaction_description",
5952
callbackUrl: "your_website_webhook_url",
6053
homeUrl: "your_website_home_url",
61-
)
54+
} as CardRequest
6255
```
6356

6457
> **Note**: we highly recommend your `callbacks` urls to be unique for each transaction.
@@ -67,32 +60,39 @@ $card = new CardRequest(
6760
Once called, Flexpay will send a payment request to the user's mobile money account, and the user will have to confirm the payment on their phone.
6861
after that the payment will be processed and the callback url will be called with the transaction details.
6962

70-
```php
71-
$response = $flexpay->pay($mobile);
63+
```typescript
64+
const response = flexpay.pay(mobile);
7265
```
7366

7467
### Visa Card Payment
7568
You can set up card payment via VPOS features, which is typically used for online payments.
7669
it's a gateway that allows you to accept payments from your customers using their credit cards.
7770

78-
```php
79-
$response = $flexpay->pay($card);
80-
// redirect to $response->url to complete the payment
71+
```typescript
72+
const response = flexpay.pay(card);
73+
// redirect to response.url to complete the payment
8174
```
8275

8376
#### **handling callback (callbackUrl, approveUrl, cancelUrl, declineUrl)**
8477
Flexpay will send a POST request to the defined callbackUrl and the response will contain the transaction details.
8578
you can use the following code to handle the callback by providing incoming data as array.
8679

8780
```php
88-
$state = $flexpay->handleCallback($_POST);
89-
$state->isSuccessful(); // true or false
81+
const webhook = flexpay.handleCallback(req.body);
82+
flexpay.isSuccessful(webhook) // true or false
9083
````
9184

9285
### Check Transaction state
9386
You don't trust webhook ? you can always check the transaction state by providing the order number.
9487

9588
```php
96-
$state = $flexpay->check($payment->orderNumber);
97-
$state->isSuccessful(); // true or false
89+
const tx = flexpay.check(mobile.orderNumber);
90+
flexpay.isSuccessful(tx) // true or false
9891
```
92+
93+
## Contributors
94+
95+
<a href="https://github.com/devscast/flexpay-tz/graphs/contributors" title="show all contributors">
96+
<img src="https://contrib.rocks/image?repo=devscast/flexpay-ts" alt="contributors"/>
97+
</a>
98+

0 commit comments

Comments
 (0)