Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 676 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
676 lars 1
# Laravel PayPal
2
 
3
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
4
[![Latest Version on Packagist](https://img.shields.io/packagist/v/srmklive/paypal.svg?style=flat-square)](https://packagist.org/packages/srmklive/paypal)
5
[![Total Downloads](https://img.shields.io/packagist/dt/srmklive/paypal.svg?style=flat-square)](https://packagist.org/packages/srmklive/paypal)
6
[![StyleCI](https://github.styleci.io/repos/43671533/shield?branch=v2.0)](https://github.styleci.io/repos/43671533?branch=v2.0)
7
![Tests](https://github.com/srmklive/laravel-paypal/workflows/TestsV3/badge.svg)
8
[![Coverage Status](https://coveralls.io/repos/github/srmklive/laravel-paypal/badge.svg?branch=v3.0)](https://coveralls.io/github/srmklive/laravel-paypal?branch=v3.0)
9
[![Code Quality](https://scrutinizer-ci.com/g/srmklive/laravel-paypal/badges/quality-score.png?b=v3.0)](https://scrutinizer-ci.com/g/srmklive/laravel-paypal/?branch=v3.0)
10
 
11
- [Documentation](#introduction)
12
- [Usage](#usage)
13
- [Support](#support)
14
 
15
 
16
<a name="introduction"></a>
17
## Documentation
18
 
19
The documentation for the package can be viewed by clicking the following link:
20
 
21
[https://srmklive.github.io/laravel-paypal/docs.html](https://srmklive.github.io/laravel-paypal/docs.html)
22
 
23
<a name="usage"></a>
24
## Usage
25
 
26
Following are some ways through which you can access the paypal provider:
27
 
28
```php
29
// Import the class namespaces first, before using it directly
30
use Srmklive\PayPal\Services\PayPal as PayPalClient;
31
 
32
$provider = new PayPalClient;
33
 
34
// Through facade. No need to import namespaces
35
$provider = \PayPal::setProvider();
36
```
37
 
38
<a name="usage-paypal-api-configuration"></a>
39
## Configuration File
40
 
41
The configuration file **paypal.php** is located in the **config** folder. Following are its contents when published:
42
 
43
```php
44
return [
45
    'mode'    => env('PAYPAL_MODE', 'sandbox'), // Can only be 'sandbox' Or 'live'. If empty or invalid, 'live' will be used.
46
    'sandbox' => [
47
        'client_id'         => env('PAYPAL_SANDBOX_CLIENT_ID', ''),
48
        'client_secret'     => env('PAYPAL_SANDBOX_CLIENT_SECRET', ''),
49
        'app_id'            => 'APP-80W284485P519543T',
50
    ],
51
    'live' => [
52
        'client_id'         => env('PAYPAL_LIVE_CLIENT_ID', ''),
53
        'client_secret'     => env('PAYPAL_LIVE_CLIENT_SECRET', ''),
54
        'app_id'            => env('PAYPAL_LIVE_APP_ID', ''),
55
    ],
56
 
57
    'payment_action' => env('PAYPAL_PAYMENT_ACTION', 'Sale'), // Can only be 'Sale', 'Authorization' or 'Order'
58
    'currency'       => env('PAYPAL_CURRENCY', 'USD'),
59
    'notify_url'     => env('PAYPAL_NOTIFY_URL', ''), // Change this accordingly for your application.
60
    'locale'         => env('PAYPAL_LOCALE', 'en_US'), // force gateway language  i.e. it_IT, es_ES, en_US ... (for express checkout only)
61
    'validate_ssl'   => env('PAYPAL_VALIDATE_SSL', true), // Validate SSL when creating api client.
62
];
63
```
64
 
65
## Override PayPal API Configuration
66
 
67
You can override PayPal API configuration by calling `setApiCredentials` method:
68
 
69
```php
991 lars 70
$config = [
71
    'mode'    => 'live',
72
    'live' => [
73
        'client_id'         => 'PAYPAL_LIVE_CLIENT_ID',
74
        'client_secret'     => 'PAYPAL_LIVE_CLIENT_SECRET',
75
        'app_id'            => 'PAYPAL_LIVE_APP_ID',
76
    ],
77
 
78
    'payment_action' => 'Sale',
79
    'currency'       => 'USD',
80
    'notify_url'     => 'https://your-site.com/paypal/notify',
81
    'locale'         => 'en_US',
82
    'validate_ssl'   => true,
83
];
676 lars 84
$provider->setApiCredentials($config);
85
```
86
 
87
 
88
<a name="usage-paypal-get-access-token"></a>
89
## Get Access Token
90
 
91
After setting the PayPal API configuration by calling `setApiCredentials` method. You need to get access token before performing any API calls
92
 
93
```php
94
$provider->getAccessToken();
95
```
96
 
97
 
98
<a name="usage-currency"></a>
99
## Set Currency
100
 
101
By default, the currency used is `USD`. If you wish to change it, you may call `setCurrency` method to set a different currency before calling any respective API methods:
102
 
103
```php
104
$provider->setCurrency('EUR');
105
```
106
 
107
<a name="usage-helpers"></a>
108
## Helper Methods
109
 
110
> Please note that in the examples below, the call to `addPlanTrialPricing` is optional and it can be omitted when you are creating subscriptions without trial period.
111
 
112
> `setReturnAndCancelUrl()` is optional. If you set urls you have to use real domains. e.g. localhost, project.test does not work.
113
 
114
### Create Recurring Daily Subscription
115
 
116
```php
117
$response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
118
            ->addPlanTrialPricing('DAY', 7)
119
            ->addDailyPlan('Demo Plan', 'Demo Plan', 1.50)
120
            ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
121
            ->setupSubscription('John Doe', 'john@example.com', '2021-12-10');
122
```
123
 
124
### Create Recurring Weekly Subscription
125
 
126
```php
127
$response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
128
            ->addPlanTrialPricing('DAY', 7)
129
            ->addWeeklyPlan('Demo Plan', 'Demo Plan', 30)
130
            ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
131
            ->setupSubscription('John Doe', 'john@example.com', '2021-12-10');
132
```
133
 
134
### Create Recurring Monthly Subscription
135
 
136
```php
137
$response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
138
            ->addPlanTrialPricing('DAY', 7)
139
            ->addMonthlyPlan('Demo Plan', 'Demo Plan', 100)
140
            ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
141
            ->setupSubscription('John Doe', 'john@example.com', '2021-12-10');
142
```
143
 
144
### Create Recurring Annual Subscription
145
 
146
```php
147
$response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
148
            ->addPlanTrialPricing('DAY', 7)
149
            ->addAnnualPlan('Demo Plan', 'Demo Plan', 600)
150
            ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
151
            ->setupSubscription('John Doe', 'john@example.com', '2021-12-10');
152
```
153
 
154
### Create Recurring Subscription with Custom Intervals
155
 
156
```php
157
$response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
158
            ->addCustomPlan('Demo Plan', 'Demo Plan', 150, 'MONTH', 3)
159
            ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
160
            ->setupSubscription('John Doe', 'john@example.com', '2021-12-10');
161
```
162
 
163
### Create Subscription by Existing Product & Billing Plan
164
 
165
```php
166
$response = $this->client->addProductById('PROD-XYAB12ABSB7868434')
167
    ->addBillingPlanById('P-5ML4271244454362WXNWU5NQ')
168
    ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
169
    ->setupSubscription('John Doe', 'john@example.com', $start_date);
170
```
171
 
172
<a name="support"></a>
173
## Support
174
 
175
This version supports Laravel 6 or greater.
176
* In case of any issues, kindly create one on the [Issues](https://github.com/srmklive/laravel-paypal/issues) section.
177
* If you would like to contribute:
178
  * Fork this repository.
179
  * Implement your features.
180
  * Generate pull request.
181