Skip to content

Commit 5a6cb29

Browse files
chore:update readme
1 parent 888e708 commit 5a6cb29

1 file changed

Lines changed: 32 additions & 16 deletions

File tree

README.md

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
## Installation
1818

19-
Add this line to your application's Gemfile:
19+
Add this to your application's Gemfile:
2020

2121
```ruby
2222
gem "paystack-ruby"
@@ -34,10 +34,22 @@ Or install directly:
3434
gem install paystack-ruby
3535
```
3636

37+
---
38+
## Configuration
39+
40+
`Paystack::Client` takes your secret key as its only argument:
41+
42+
```ruby
43+
paystack = Paystack::Client.new(ENV.fetch("PAYSTACK_SECRET_KEY"))
44+
```
45+
Use your Test Secret Key (`sk_test_...`) for development and Live Secret Key (`sk_live_...`) in production. Get them from your [Paystack Dashboard](https://dashboard.paystack.com/#/login).
46+
3747
---
3848

3949
## Quick Start
4050

51+
Initialize a transaction and send the customer to `authorization_url` to pay:
52+
4153
```ruby
4254
require "paystack"
4355

@@ -53,19 +65,16 @@ result = paystack.transaction.initialize(
5365
puts result.data[:authorization_url]
5466
```
5567

56-
---
57-
58-
## Configuration
59-
60-
Initialize `Paystack::Client` with your secret key:
68+
Once the customer is redirected back, verify the transaction before you treat it as paid; never trust the redirect alone:
6169

6270
```ruby
63-
paystack = Paystack::Client.new("sk_live_xxxxxxxxxxxx")
71+
result = paystack.transaction.verify(reference)
72+
73+
if result.data[:status] == "success"
74+
# fulfil the order
75+
end
6476
```
6577

66-
| Option | Type | Required | Default |
67-
|---|---|---|---|
68-
| `api_key` | `String` |||
6978

7079
---
7180

@@ -85,21 +94,28 @@ response.meta # Hash / nil
8594

8695
## Error Handling
8796

88-
API failures raise typed exceptions:
97+
API failures raise a `Paystack::Error`, carrying the HTTP status and response body:
8998

9099
```ruby
91100
begin
92101
paystack.transaction.initialize({ email: "customer@example.com", amount: 100_000 })
93-
rescue Paystack::AuthenticationError,
94-
Paystack::ValidationError,
95-
Paystack::NotFoundError,
96-
Paystack::RateLimitError,
97-
Paystack::ServerError => e
102+
rescue Paystack::Error => e
98103
puts e.message
99104
puts e.http_status
100105
end
101106
```
102107

108+
If you need to branch on failure type, rescue the specific subclass instead — `Paystack::AuthenticationError`, `ValidationError`, `NotFoundError`, `RateLimitError`, or `ServerError`:
109+
110+
```ruby
111+
begin
112+
paystack.transaction.initialize({ email: "customer@example.com", amount: 100_000 })
113+
rescue Paystack::RateLimitError
114+
sleep(1)
115+
retry
116+
end
117+
```
118+
103119
---
104120

105121
## API Reference

0 commit comments

Comments
 (0)