Subversion-Projekte lars-tiefland.laravel_shop

Revision

Zur aktuellen Revision | Details | 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
70
$provider->setApiCredentials($config);
71
```
72
 
73
 
74
<a name="usage-paypal-get-access-token"></a>
75
## Get Access Token
76
 
77
After setting the PayPal API configuration by calling `setApiCredentials` method. You need to get access token before performing any API calls
78
 
79
```php
80
$provider->getAccessToken();
81
```
82
 
83
 
84
<a name="usage-currency"></a>
85
## Set Currency
86
 
87
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:
88
 
89
```php
90
$provider->setCurrency('EUR');
91
```
92
 
93
<a name="usage-helpers"></a>
94
## Helper Methods
95
 
96
> 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.
97
 
98
> `setReturnAndCancelUrl()` is optional. If you set urls you have to use real domains. e.g. localhost, project.test does not work.
99
 
100
### Create Recurring Daily Subscription
101
 
102
```php
103
$response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
104
            ->addPlanTrialPricing('DAY', 7)
105
            ->addDailyPlan('Demo Plan', 'Demo Plan', 1.50)
106
            ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
107
            ->setupSubscription('John Doe', 'john@example.com', '2021-12-10');
108
```
109
 
110
### Create Recurring Weekly Subscription
111
 
112
```php
113
$response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
114
            ->addPlanTrialPricing('DAY', 7)
115
            ->addWeeklyPlan('Demo Plan', 'Demo Plan', 30)
116
            ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
117
            ->setupSubscription('John Doe', 'john@example.com', '2021-12-10');
118
```
119
 
120
### Create Recurring Monthly Subscription
121
 
122
```php
123
$response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
124
            ->addPlanTrialPricing('DAY', 7)
125
            ->addMonthlyPlan('Demo Plan', 'Demo Plan', 100)
126
            ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
127
            ->setupSubscription('John Doe', 'john@example.com', '2021-12-10');
128
```
129
 
130
### Create Recurring Annual Subscription
131
 
132
```php
133
$response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
134
            ->addPlanTrialPricing('DAY', 7)
135
            ->addAnnualPlan('Demo Plan', 'Demo Plan', 600)
136
            ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
137
            ->setupSubscription('John Doe', 'john@example.com', '2021-12-10');
138
```
139
 
140
### Create Recurring Subscription with Custom Intervals
141
 
142
```php
143
$response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
144
            ->addCustomPlan('Demo Plan', 'Demo Plan', 150, 'MONTH', 3)
145
            ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
146
            ->setupSubscription('John Doe', 'john@example.com', '2021-12-10');
147
```
148
 
149
### Create Subscription by Existing Product & Billing Plan
150
 
151
```php
152
$response = $this->client->addProductById('PROD-XYAB12ABSB7868434')
153
    ->addBillingPlanById('P-5ML4271244454362WXNWU5NQ')
154
    ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
155
    ->setupSubscription('John Doe', 'john@example.com', $start_date);
156
```
157
 
158
<a name="support"></a>
159
## Support
160
 
161
This version supports Laravel 6 or greater.
162
* In case of any issues, kindly create one on the [Issues](https://github.com/srmklive/laravel-paypal/issues) section.
163
* If you would like to contribute:
164
  * Fork this repository.
165
  * Implement your features.
166
  * Generate pull request.
167