Skip to content
This repository was archived by the owner on Jul 15, 2020. It is now read-only.

Commit 91eb120

Browse files
wip
1 parent ef8eeb8 commit 91eb120

File tree

1 file changed

+96
-225
lines changed

1 file changed

+96
-225
lines changed

README.md

Lines changed: 96 additions & 225 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<div align="center">
2-
<!-- <img src="https://cloudinary-res.cloudinary.com/image/upload/c_scale,w_86/v1/logo/for_white_bg/cloudinary_vertical_logo_for_white_bg.png"> -->
3-
<h3> Laravel Cloudinary </h3>
2+
<h2> Laravel Cloudinary </h2>
43
</div>
54

65
<p align="center">
@@ -18,187 +17,15 @@
1817
</a>
1918
</p>
2019

21-
<p>Laravel-Cloudinary is a package for easily uploading, optimizing, transforming and attaching media files to Eloquent models with Laravel.</p>
20+
> A Laravel Package for easily uploading, optimizing, transforming and delivering media files with Cloudinary. It provides a fluent and expressive API to easily attach your media files to Eloquent models.
2221
23-
## Installation
24-
25-
[PHP](https://php.net) 5.4+ or [HHVM](http://hhvm.com) 3.3+, and [Composer](https://getcomposer.org) are required.
26-
27-
To get the latest version of Laravel Cloudinary, simply require it
28-
29-
```bash
30-
composer require unicodeveloper/laravel-cloudinary
31-
```
32-
33-
Or add the following line to the require block of your `composer.json` file.
34-
35-
```
36-
"unicodeveloper/laravel-cloudinary": "1.0.0-beta"
37-
```
38-
39-
You'll then need to run `composer install` or `composer update` to download it and have the autoloader updated.
40-
41-
42-
Once Laravel Cloudinary is installed, you need to register the service provider. Open up `config/app.php` and add the following to the `providers` key.
43-
44-
```php
45-
'providers' => [
46-
...
47-
Unicodeveloper\Cloudinary\CloudinaryServiceProvider::class,
48-
...
49-
]
50-
```
51-
52-
> If you use **Laravel >= 5.5** you can skip this step and go to [**`configuration`**](https://github.com/unicodeveloper/laravel-cloudinary#configuration)
53-
54-
* `Unicodeveloper\Cloudinary\CloudinaryServiceProvider::class`
55-
56-
Also, register the Facade like so:
57-
58-
```php
59-
'aliases' => [
60-
...
61-
'Cloudinary' => Unicodeveloper\Cloudinary\Facades\Cloudinary::class,
62-
...
63-
]
64-
```
65-
66-
## Configuration
67-
68-
You can publish the configuration file using this command:
69-
70-
```bash
71-
php artisan vendor:publish --provider="Unicodeveloper\Cloudinary\CloudinaryServiceProvider"
72-
```
73-
74-
A configuration-file named `cloudinary.php` with some sensible defaults will be placed in your `config` directory:
75-
76-
```php
77-
<?php
78-
return [
79-
'notification_url' => env('CLOUDINARY_NOTIFICATION_URL', ''),
80-
81-
'account_details' => [
82-
83-
'account' => [
84-
/**
85-
* Cloud Name From Cloudinary Dashboard
86-
*
87-
*/
88-
'cloud_name' => env('CLOUDINARY_CLOUD_NAME'),
89-
90-
/**
91-
* API Key From Cloudinary Dashboard
92-
*
93-
*/
94-
'api_key' => env('CLOUDINARY_API_KEY'),
95-
96-
/**
97-
* API Secret From Cloudinary Dashboard
98-
*
99-
*/
100-
'api_secret' => env('CLOUDINARY_API_SECRET'),
101-
102-
/**
103-
* Upload Preset From Cloudinary Dashboard
104-
*
105-
*/
106-
'upload_preset' => env('CLOUDINARY_UPLOAD_PRESET')
107-
],
108-
109-
'url' => [
110-
'secure' => true
111-
]
112-
]
113-
];
114-
```
11522

11623
## Usage
11724

118-
Open your .env file and add your Cloudinary cloud name, api key, api secret, and upload preset like so:
25+
Upload a file to Cloudinary:
11926

12027
```php
121-
CLOUDINARY_CLOUD_NAME=xxxxxxxxxxxxx
122-
CLOUDINARY_API_KEY=xxxxxxxxxxxxx
123-
CLOUDINARY_API_SECRET=xxxxxxxxxxxxx
124-
CLOUDINARY_UPLOAD_PRESET=xxxxxxxxxxxxx
125-
CLOUDINARY_NOTIFICATION_URL=
126-
```
12728

128-
***Note:** You need to get these credentials from your [Cloudinary Dashboard](https://cloudinary.com/console)*
129-
130-
*If you are using a hosting service like heroku,forge,digital ocean, etc, please ensure to add the above details to your configuration variables.*
131-
132-
Set up routes and controller methods like so:
133-
134-
Note: Make sure you have `/payment/callback` registered in Paystack Dashboard [https://dashboard.paystack.co/#/settings/developer](https://dashboard.paystack.co/#/settings/developer) like so:
135-
136-
![payment-callback](https://cloud.githubusercontent.com/assets/2946769/12746754/9bd383fc-c9a0-11e5-94f1-64433fc6a965.png)
137-
138-
```php
139-
// Laravel 5.1.17 and above
140-
Route::post('/pay', 'PaymentController@redirectToGateway')->name('pay');
141-
```
142-
143-
OR
144-
145-
```php
146-
Route::post('/pay', [
147-
'uses' => 'PaymentController@redirectToGateway',
148-
'as' => 'pay'
149-
]);
150-
```
151-
152-
```php
153-
Route::get('/payment/callback', 'PaymentController@handleGatewayCallback');
154-
```
155-
156-
OR
157-
158-
```php
159-
// Laravel 5.0
160-
Route::get('payment/callback', [
161-
'uses' => 'PaymentController@handleGatewayCallback'
162-
]);
163-
```
164-
165-
```php
166-
<?php
167-
168-
namespace App\Http\Controllers;
169-
170-
use Illuminate\Http\Request;
171-
172-
use App\Http\Requests;
173-
use App\Http\Controllers\Controller;
174-
use Paystack;
175-
176-
class PaymentController extends Controller
177-
{
178-
179-
/**
180-
* Redirect the User to Paystack Payment Page
181-
* @return Url
182-
*/
183-
public function redirectToGateway()
184-
{
185-
return Paystack::getAuthorizationUrl()->redirectNow();
186-
}
187-
188-
/**
189-
* Obtain Paystack payment information
190-
* @return void
191-
*/
192-
public function handleGatewayCallback()
193-
{
194-
$paymentDetails = Paystack::getPaymentData();
195-
196-
dd($paymentDetails);
197-
// Now you have the payment details,
198-
// you can store the authorization_code in your db to allow for recurrent subscriptions
199-
// you can then redirect or do whatever you want
200-
}
201-
}
20229
```
20330

20431
Let me explain the fluent methods this package provides a bit here.
@@ -324,73 +151,117 @@ Paystack::updateSubAccount();
324151
paystack()->updateSubAccount();
325152
```
326153

327-
A sample form will look like so:
328-
329-
```html
330-
<form method="POST" action="{{ route('pay') }}" accept-charset="UTF-8" class="form-horizontal" role="form">
331-
<div class="row" style="margin-bottom:40px;">
332-
<div class="col-md-8 col-md-offset-2">
333-
<p>
334-
<div>
335-
Lagos Eyo Print Tee Shirt
336-
₦ 2,950
337-
</div>
338-
</p>
339-
<input type="hidden" name="email" value="otemuyiwa@gmail.com"> {{-- required --}}
340-
<input type="hidden" name="orderID" value="345">
341-
<input type="hidden" name="amount" value="800"> {{-- required in kobo --}}
342-
<input type="hidden" name="quantity" value="3">
343-
<input type="hidden" name="currency" value="NGN">
344-
<input type="hidden" name="metadata" value="{{ json_encode($array = ['key_name' => 'value',]) }}" > {{-- For other necessary things you want to add to your payload. it is optional though --}}
345-
<input type="hidden" name="reference" value="{{ Paystack::genTranxRef() }}"> {{-- required --}}
346-
{{ csrf_field() }} {{-- works only when using laravel 5.1, 5.2 --}}
347-
348-
<input type="hidden" name="_token" value="{{ csrf_token() }}"> {{-- employ this in place of csrf_field only in laravel 5.0 --}}
349-
350-
351-
<p>
352-
<button class="btn btn-success btn-lg btn-block" type="submit" value="Pay Now!">
353-
<i class="fa fa-plus-circle fa-lg"></i> Pay Now!
354-
</button>
355-
</p>
356-
</div>
357-
</div>
358-
</form>
154+
## Installation
155+
156+
[PHP](https://php.net) 5.4+ or [HHVM](http://hhvm.com) 3.3+, and [Composer](https://getcomposer.org) are required.
157+
158+
To get the latest version of Laravel Cloudinary, simply require it
159+
160+
```bash
161+
composer require unicodeveloper/laravel-cloudinary
162+
```
163+
164+
Or add the following line to the require block of your `composer.json` file.
165+
166+
```
167+
"unicodeveloper/laravel-cloudinary": "1.0.0-beta"
359168
```
360169

361-
When clicking the submit button the customer gets redirected to the Paystack site.
170+
You'll then need to run `composer install` or `composer update` to download it and have the autoloader updated.
362171

363-
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.
364172

365-
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.
173+
Once Laravel Cloudinary is installed, you need to register the service provider. Open up `config/app.php` and add the following to the `providers` key.
366174

367-
We must validate if the redirect to our site is a valid request (we don't want imposters to wrongfully place non-paid order).
175+
```php
176+
'providers' => [
177+
...
178+
Unicodeveloper\Cloudinary\CloudinaryServiceProvider::class,
179+
...
180+
]
181+
```
368182

369-
In the controller that handles the request coming from the payment provider, we have
183+
> If you use **Laravel >= 5.5** you can skip this step and go to [**`configuration`**](https://github.com/unicodeveloper/laravel-cloudinary#configuration)
370184
371-
`Paystack::getPaymentData()` - This function calls the verification methods and ensure it is a valid transction else it throws an exception.
185+
* `Unicodeveloper\Cloudinary\CloudinaryServiceProvider::class`
372186

373-
You can test with these details
187+
Also, register the Facade like so:
188+
189+
```php
190+
'aliases' => [
191+
...
192+
'Cloudinary' => Unicodeveloper\Cloudinary\Facades\Cloudinary::class,
193+
...
194+
]
195+
```
196+
197+
## Configuration
198+
199+
You can publish the configuration file using this command:
374200

375201
```bash
376-
Card Number: 4123450131001381
377-
Expiry Date: any date in the future
378-
CVV: 883
202+
php artisan vendor:publish --provider="Unicodeveloper\Cloudinary\CloudinaryServiceProvider"
379203
```
380204

381-
## Todo
205+
A configuration-file named `cloudinary.php` with some sensible defaults will be placed in your `config` directory:
206+
207+
```php
208+
<?php
209+
return [
210+
'notification_url' => env('CLOUDINARY_NOTIFICATION_URL', ''),
211+
212+
'account_details' => [
382213

383-
* Charge Returning Customers
384-
* Add Comprehensive Tests
385-
* Implement Transaction Dashboard to see all of the transactions in your laravel app
214+
'account' => [
215+
/**
216+
* Cloud Name From Cloudinary Dashboard
217+
*
218+
*/
219+
'cloud_name' => env('CLOUDINARY_CLOUD_NAME'),
386220

387-
## Contributing
221+
/**
222+
* API Key From Cloudinary Dashboard
223+
*
224+
*/
225+
'api_key' => env('CLOUDINARY_API_KEY'),
226+
227+
/**
228+
* API Secret From Cloudinary Dashboard
229+
*
230+
*/
231+
'api_secret' => env('CLOUDINARY_API_SECRET'),
232+
233+
/**
234+
* Upload Preset From Cloudinary Dashboard
235+
*
236+
*/
237+
'upload_preset' => env('CLOUDINARY_UPLOAD_PRESET')
238+
],
239+
240+
'url' => [
241+
'secure' => true
242+
]
243+
]
244+
];
245+
```
246+
247+
Open your .env file and add your Cloudinary cloud name, api key, api secret, and upload preset like so:
248+
249+
```php
250+
CLOUDINARY_CLOUD_NAME=xxxxxxxxxxxxx
251+
CLOUDINARY_API_KEY=xxxxxxxxxxxxx
252+
CLOUDINARY_API_SECRET=xxxxxxxxxxxxx
253+
CLOUDINARY_UPLOAD_PRESET=xxxxxxxxxxxxx
254+
CLOUDINARY_NOTIFICATION_URL=
255+
```
256+
257+
***Note:** You need to get these credentials from your [Cloudinary Dashboard](https://cloudinary.com/console)*
258+
259+
*If you are using a hosting service like heroku,forge,digital ocean, etc, please ensure to add the above details to your configuration variables.*
388260

389-
Please feel free to fork this package and contribute by submitting a pull request to enhance the functionalities.
390261

391262
## How can I thank you?
392263

393-
Why not star the github repo? I'd love the attention! Why not share the link for this repository on Twitter or HackerNews? Spread the word!
264+
Why not star the GitHub repo? I'd love the attention! Why not share the link for this repository on Twitter or HackerNews? Spread the word!
394265

395266
Don't forget to [follow me on twitter](https://twitter.com/unicodeveloper)!
396267

0 commit comments

Comments
 (0)