You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A configuration-file named `paystack.php` with some sensible defaults will be placed in your `config` directory:
46
+
47
+
```php
48
+
<?php
49
+
50
+
return [
51
+
52
+
/**
53
+
* Public Key From Paystack Dashboard
54
+
*
55
+
*/
56
+
'publicKey' => getenv('PAYSTACK_PUBLIC_KEY'),
57
+
58
+
/**
59
+
* Secret Key From Paystack Dashboard
60
+
*
61
+
*/
62
+
'secretKey' => getenv('PAYSTACK_SECRET_KEY'),
63
+
64
+
/**
65
+
* Paystack Payment URL
66
+
*
67
+
*/
68
+
'paymentUrl' => getenv('PAYSTACK_PAYMENT_URL'),
69
+
70
+
/**
71
+
* Optional email address of the merchant
72
+
*
73
+
*/
74
+
'merchantEmail' => getenv('MERCHANT_EMAIL'),
75
+
76
+
/**
77
+
* Unique transaction reference
78
+
*/
79
+
'reference' => 'payref'.time().'tranx',
80
+
];
81
+
```
82
+
83
+
84
+
##General payment flow
85
+
86
+
Though there are multiple ways to pay an order, most payment gateways except you to follow the following flow in your checkout process:
87
+
88
+
###1. The customer is redirected to the payment provider
89
+
After the customer has gone through the checkout process and is ready to pay, the customer must be redirected to site of the payment provider.
90
+
91
+
The redirection is accomplished by submitting a form with some hidden fields. The form must post to the site of the payment provider. The hidden fields minimally specify the amount that must be paid, the order id and a hash.
92
+
93
+
The hash is calculated using the hidden form fields and a non-public secret. The hash used by the payment provider to verify if the request is valid.
94
+
95
+
96
+
###2. The customer pays on the site of the payment provider
97
+
The customer arrived on the site of the payment provider and gets to choose a payment method. All steps necessary to pay the order are taken care of by the payment provider.
98
+
99
+
###3. The customer gets redirected back
100
+
After having paid the order the customer is redirected back. In the redirection request to the shop-site some values are returned. The values are usually the order id, a paymentresult and a hash.
101
+
102
+
The hash is calculated out of some of the fields returned and a secret non-public value. This hash is used to verify if the request is valid and comes from the payment provider. It is paramount that this hash is thoroughly checked.
103
+
104
+
The payment result can be something like "payment ok", "customer cancelled payment" or "payment declined".
105
+
106
+
45
107
## Usage
46
108
109
+
1. Open your .env file and add your public key, secret key, merchant email and payment url like so:
When clicking the submit button the customer gets redirected to the Paystack site.
194
+
195
+
So now we've redirected the customer to Paystack. The customer did some actions there (hopefully he or she paid the order) and now gets redirected back to our shop site.
196
+
197
+
Paystack will redirect the customer to the url of the route that is specified in the Callback URL of the Web Hooks section on Paystack dashboard.
198
+
199
+
We must validate if the redirect to our site is a valid request (we don't want imposters to wrongfully place non-paid order).
200
+
201
+
In the controller that handles the request coming from the payment provider, we have
202
+
203
+
`Paystack::getPaymentData()` - This function calls the verification methods and ensure it is a valid transction else it throws an exception.
204
+
47
205
## Contributing
48
206
49
207
Please feel free to fork this package and contribute by submitting a pull request to enhance the functionalities.
0 commit comments