Skip to content

Commit 902b2cf

Browse files
Merge pull request #14 from appinlet/release/1.1.5
## 1.1.5 - 2023-10-11
2 parents 41bf139 + 8564e15 commit 902b2cf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+3004
-255
lines changed

CHANGELOG.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
# Changelog
22

3+
## 1.1.5 - 2023-10-11
4+
* Update for PHP 8.1.
5+
* Bug fixes and code quality improvements.
6+
7+
## 1.1.4 - 2022-12-20
8+
* Fix issues in signature generation.
9+
310
## 1.1.3 - 2022-08-03
4-
* Add offset and limit to transaction history
11+
* Add offset and limit to transaction history.
512

613
## 1.1.2 - 2021-03-15
7-
* Lower httpguzzle version expectations and use passphrase
14+
* Lower httpguzzle version expectations and use passphrase.
815

916
## 1.1.1 - 2021-03-11
10-
* Fix for payload parameters with a zero value
17+
* Fix for payload parameters with a zero value.
1118

1219
## 1.1.0 - 2021-03-08
13-
* Add Refunds API
14-
* Add Card update
15-
* Add sort parameters to custom payment signature generation
16-
* Update Onsite not available in sandbox mode
20+
* Add Refunds API.
21+
* Add Card update.
22+
* Add sort parameters to custom payment signature generation.
23+
* Update Onsite not available in sandbox mode.
1724

1825
## 1.0.1 - 2021-03-03
19-
* Passphrase bug fix
26+
* Passphrase bug fix.
2027

2128
## 1.0.0 - 2020-11-23
22-
* Initial Release
29+
* Initial Release.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2016-2022 PayFast (https://www.payfast.co.za)
3+
Copyright (c) 2016-2023 Payfast (https://payfast.io)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 239 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,241 @@
11
# payfast-php-sdk
22

3-
This repository is no longer supported and has been archived.
3+
The Payfast PHP SDK provides an easy-to-use library for integrating Payfast payments into your project.
4+
This includes Custom Integration, Onsite Integration and all APIs.
5+
6+
## Requirements
7+
8+
PHP 8.1 and later.
9+
10+
## Documentation
11+
12+
See the [Developer Docs](https://developers.payfast.co.za/docs)
13+
14+
## Composer
15+
16+
You can install the library via [Composer](http://getcomposer.org/). Run the following command:
17+
18+
```bash
19+
composer require payfast/payfast-php-sdk
20+
```
21+
22+
To use the library, use Composer's [autoload](https://getcomposer.org/doc/01-basic-usage.md#autoloading):
23+
24+
```php
25+
require_once('vendor/autoload.php');
26+
```
27+
28+
## Getting Started
29+
30+
### Custom Integration
31+
32+
Build a checkout form and receive payments securely from the Payfast payment platform.
33+
34+
**NB!** The default value of 'testMode' is true.
35+
36+
See the [Developer Docs](https://developers.payfast.co.za/docs#quickstart)
37+
38+
```php
39+
try {
40+
$payfast = new PayfastPayment(
41+
[
42+
'merchantId' => '10000100',
43+
'merchantKey' => '46f0cd694581a',
44+
'passPhrase' => 'jt7NOE43FZPn',
45+
'testMode' => true
46+
]
47+
);
48+
49+
$data = [
50+
'amount' => '100.00',
51+
'item_name' => 'Order#123'
52+
];
53+
54+
echo $payfast->custom->createFormFields($data, ['value' => 'PAY NOW', 'class' => 'btn']);
55+
} catch(Exception $e) {
56+
echo 'There was an exception: '.$e->getMessage();
57+
}
58+
```
59+
60+
### Onsite Payments
61+
62+
Integrate Payfast’s secure payment engine directly into your checkout page.
63+
64+
**NB!** The default value of 'testMode' is false. Otherwise we get the Exception: "_**There was an exception: Sorry but Onsite is not available in Sandbox mode**_"
65+
66+
See the [Developer Docs](https://developers.payfast.co.za/docs#onsite_payments)
67+
68+
```php
69+
// Include: <script src="https://www.payfast.co.za/onsite/engine.js"></script>
70+
71+
try {
72+
$payfast = new PayfastPayment(
73+
[
74+
'merchantId' => '10000100',
75+
'merchantKey' => '46f0cd694581a',
76+
'passPhrase' => 'jt7NOE43FZPn',
77+
'testMode' => false
78+
]
79+
);
80+
81+
$data = [
82+
'amount' => '100.00',
83+
'item_name' => 'Order#123'
84+
];
85+
86+
// Generate payment identifier
87+
$identifier = $payfast->onsite->generatePaymentIdentifier($data);
88+
89+
if($identifier!== null){
90+
echo '<script type="text/javascript">window.payfast_do_onsite_payment({"uuid":"'.$identifier.'"});</script>';
91+
}
92+
} catch(Exception $e) {
93+
echo 'There was an exception: '.$e->getMessage();
94+
}
95+
```
96+
97+
### API
98+
99+
#### Recurring Billing
100+
101+
The Subscription Payments API gives Merchants the ability to interact with subscriptions on their accounts.
102+
103+
**NB!** The default value of 'testMode' is true.
104+
105+
See the [Developer Docs](https://developers.payfast.co.za/api#recurring-billing)
106+
107+
```php
108+
try {
109+
$api = new PayfastApi(
110+
[
111+
'merchantId' => '10018867',
112+
'passPhrase' => '2uU_k5q_vRS_',
113+
'testMode' => true
114+
]
115+
);
116+
117+
$fetchArray = $api->subscriptions->fetch('2afa4575-5628-051a-d0ed-4e071b56a7b0');
118+
119+
$pauseArray = $api->subscriptions->pause('2afa4575-5628-051a-d0ed-4e071b56a7b0', ['cycles' => 1]);
120+
121+
$unpauseArray = $api->subscriptions->unpause('2afa4575-5628-051a-d0ed-4e071b56a7b0');
122+
123+
$cancelArray = $api->subscriptions->cancel('2afa4575-5628-051a-d0ed-4e071b56a7b0');
124+
125+
$updateArray = $api->subscriptions->update('2afa4575-5628-051a-d0ed-4e071b56a7b0', ['cycles' => 1]);
126+
127+
$adhocArray = $api->subscriptions->adhoc('290ac9a6-25f1-cce4-5801-67a644068818', ['amount' => 500, 'item_name' => 'Test adhoc']);
128+
129+
} catch(Exception $e) {
130+
echo 'There was an exception: '.$e->getMessage();
131+
}
132+
```
133+
134+
#### Update card
135+
136+
The update card endpoint allows you to provide buyers with a link to update their card details on a Recurring Billing subscription or Tokenization charges.
137+
138+
**NB!** The default value of 'testMode' is false. Otherwise we get the Exception: "_**There was an exception: Sorry but Onsite is not available in Sandbox mode**_"
139+
140+
See the [Developer Docs](https://developers.payfast.co.za/docs#recurring_card_update)
141+
142+
```php
143+
try {
144+
$payfast = new PayfastPayment(
145+
[
146+
'merchantId' => '10000100',
147+
'merchantKey' => '46f0cd694581a',
148+
'passPhrase' => 'jt7NOE43FZPn',
149+
'testMode' => false
150+
]
151+
);
152+
153+
echo $payfast->custom->createCardUpdateLink('2afa4575-5628-051a-d0ed-4e071b56a7b0', 'https://www.example.com/return', 'Update your card', ['target' => '_blank']);
154+
155+
} catch(Exception $e) {
156+
echo 'There was an exception: '.$e->getMessage();
157+
}
158+
```
159+
160+
#### Transaction History
161+
162+
The transaction history API gives Merchants the ability to interact with their Payfast account.
163+
164+
**NB!** The default value of 'testMode' is true.
165+
166+
See the [Developer Docs](https://developers.payfast.co.za/api#transaction-history)
167+
168+
```php
169+
try {
170+
$api = new PayfastApi(
171+
[
172+
'merchantId' => '10018867',
173+
'passPhrase' => '2uU_k5q_vRS_',
174+
'testMode' => true
175+
]
176+
);
177+
178+
$rangeArray = $api->transactionHistory->range(['from' => '2020-08-01', 'to' => '2020-08-07', 'offset' => 0, 'limit' => 1000]);
179+
180+
$dailyArray = $api->transactionHistory->daily(['date' => '2020-08-07', 'offset' => 0, 'limit' => 1000]);
181+
182+
$weeklyArray = $api->transactionHistory->weekly(['date' => '2020-08-07', 'offset' => 0, 'limit' => 1000]);
183+
184+
$monthlyArray = $api->transactionHistory->monthly(['date' => '2020-08', 'offset' => 0, 'limit' => 1000]);
185+
186+
} catch(Exception $e) {
187+
echo 'There was an exception: '.$e->getMessage();
188+
}
189+
```
190+
191+
#### Credit card transaction query
192+
193+
The credit card transaction query API gives Merchants the ability to query credit card transactions.
194+
195+
**NB!** The default value of 'testMode' is true.
196+
197+
See the [Developer Docs](https://developers.payfast.co.za/api#credit-card-transactions)
198+
199+
```php
200+
try {
201+
$api = new PayfastApi(
202+
[
203+
'merchantId' => '10018867',
204+
'passPhrase' => '2uU_k5q_vRS_',
205+
'testMode' => true
206+
]
207+
);
208+
209+
$creditCardArray = $api->creditCardTransactions->fetch('1124148');
210+
211+
} catch(Exception $e) {
212+
echo 'There was an exception: '.$e->getMessage();
213+
}
214+
```
215+
216+
#### Refunds
217+
218+
The Refunds API Providing gives Merchants the ability to perform refunds on their account.
219+
220+
**NB!** The default value of 'testMode' is false. Otherwise we get the Exception: "_**There was an exception: Sorry but Onsite is not available in Sandbox mode**_"
221+
222+
See the [Developer Docs](https://developers.payfast.co.za/api#refunds)
223+
224+
```php
225+
try {
226+
$api = new PayfastApi(
227+
[
228+
'merchantId' => '10018867',
229+
'passPhrase' => '2uU_k5q_vRS_',
230+
'testMode' => false
231+
]
232+
);
233+
234+
$refundFetchArray = $api->refunds->fetch('dc0521d3-55fe-269b-fa00-b647310d760f');
235+
236+
$refundCreateArray = $api->refunds->create('dc0521d3-55fe-269b-fa00-b647310d760f', ['amount' => 50, 'reason' => 'Product returned', 'acc_type' => 'savings']);
237+
238+
} catch(Exception $e) {
239+
echo 'There was an exception: '.$e->getMessage();
240+
}
241+
```

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "payfast/payfast-php-sdk",
3-
"description": "PayFast PHP Library",
3+
"description": "Payfast PHP Library",
44
"keywords": [
55
"payfast",
66
"api",
@@ -11,19 +11,19 @@
1111
"license": "MIT",
1212
"authors": [
1313
{
14-
"name": "Claire Grant",
15-
"email": "claire.grant@payfast.co.za"
14+
"name": "Payfast",
15+
"email": "support@payfast.help"
1616
}
1717
],
1818
"minimum-stability": "stable",
1919
"require": {
20-
"php": ">=7.2.5",
20+
"php": ">=8.1",
2121
"guzzlehttp/guzzle": ">=6.0.0",
2222
"ext-json": "*"
2323
},
2424
"autoload": {
2525
"psr-4": {
26-
"PayFast\\": "lib/"
26+
"Payfast\\": "lib/"
2727
}
2828
},
2929
"require-dev": {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Checkout</title>
6+
<link rel="stylesheet" href="css/main.css">
7+
</head>
8+
<body>
9+
10+
<div class='subject'>Checkout&nbsp;&nbsp;Check<br>Checkout&nbsp;&nbsp;Check</div>
11+
12+
<div class='checkout'>
13+
<div class='order'>
14+
<h2>Onsite Checkout Demo</h2>
15+
<h5>Order #000001</h5>
16+
<ul class='order-list'>
17+
<li><img src='https://via.placeholder.com/150' alt="Product 1 image"><h4>Product 1</h4><h5>R2</h5></li>
18+
<li><img src='https://via.placeholder.com/150' alt="Product 2 image"><h4>Product 2</h4><h5>R1</h5></li>
19+
<li><img src='https://via.placeholder.com/150' alt="Product 3 image"><h4>Product 3</h4><h5>R1</h5></li>
20+
</ul>
21+
<h5>Shipping</h5><h4>R 1.00</h4>
22+
<h5 class='total'>Total</h5><h1>R 5.00</h1>
23+
24+
<div class="cancel"><h2>Payment Cancelled -> <a href="index.php">TRY AGAIN</a></h2></div>
25+
26+
</div>
27+
</div>
28+
29+
</body>
30+
</html>
31+
32+
<?php
33+

0 commit comments

Comments
 (0)