Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hypnodev committed Aug 12, 2020
0 parents commit 9b34ded
Show file tree
Hide file tree
Showing 26 changed files with 6,113 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vendor
.idea

1 change: 1 addition & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
preset: laravel
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changelog

All notable changes to `Larapal` will be documented in this file.

## Version 1.0

### Added
- Everything
18 changes: 18 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Contributing

Contributions are welcome and will be fully credited.

Contributions are accepted via Pull Requests on [Github](https://github.com/hypnodev/larapal).

## Pull Requests

- **Document any change in behaviour** - Make sure the `readme.md` and any other relevant documentation are kept up-to-date.

- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.

- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.

- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.


**Happy coding**!
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# The license

Copyright (c) 2020 Cristian Cosenza <me@cristiancosenza.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
173 changes: 173 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
# Larapal

[![Latest Version on Packagist][ico-version]][link-packagist]
[![Total Downloads][ico-downloads]][link-downloads]

A modern, easy and fluent way to allow your clients to pay with PayPal.

## Installation

Via Composer

``` bash
$ composer require hypnodev/larapal
```

Publish the configuration with command:
```bash
$ php artisan vendor:publish --provider="hypnodev\Larapal\LarapalServiceProvider"
```

Add these keys in your .env:
```dotenv
PAYPAL_MODE=sandbox
PAYPAL_SANDBOX_ID=
PAYPAL_SANDBOX_SECRET=
PAYPAL_PRODUCTION_ID=
PAYPAL_PRODUCTION_SECRET=
```
_If you don't have yet credentials for PayPal API, please refer to [Get Started - PayPal Developer](https://developer.paypal.com/docs/api/overview/#get-credentials)_

## Usage
Add `BillableWithPaypal` trait to your User model
```php
<?php

namespace App;

use hypnodev\Larapal\Traits\BillableWithPaypal;
// ...

class User extends Authenticatable
{
use Notifiable, BillableWithPaypal;

// ...
}
```

This will add `chargeWithPaypal`, `subscribeWithPaypal`, `getPaypalCurrency`, `getShippingFields` to your user.

Then you can charge your user with method:
```php
<?php
auth()->user()->chargeWithPaypal('Charge description', [ // Array of items
['name' => 'pkg base', 'description' => 'base package', 'price' => 10.00, 'tax' => 2]
]);

// If your charge has shipping, you need to add an extra param with name and amount
auth()->user()->chargeWithPaypal('Charge description', [ // Array of items
['name' => 'pkg base', 'description' => 'base package', 'price' => 10.00, 'tax' => 2]
], [ // Shipping
'name' => 'Courier name',
'amount' => 100.50,
'address' => [ // Optional, you can skip this key
'address' => '4178 Libby Street',
'city' => 'Hermosa Beach',
'state' => 'CA',
'postal_code' => '90254',
'country' => 'USA'
]
]);
```

Or for subscription:
```php
auth()->user()->subscribeWithPaypal('Plan id');
```
_You can create a plan under "App Center" in your PayPal Merchant Dashboard_

If you need to charge user with another currency different from the configuration, you can override `getPaypalCurrency` method:
```php
<?php

namespace App;

use hypnodev\Larapal\Traits\BillableWithPaypal;
// ...

class User extends Authenticatable
{
use Notifiable, BillableWithPaypal;

// ...

/**
* @inheritDoc
*/
protected function getPaypalCurrency(): string
{
return 'USD';
}
}
```

You can set default shipping info with `getShippingFields` method
```php
<?php

namespace App;

use hypnodev\Larapal\Traits\BillableWithPaypal;
// ...

class User extends Authenticatable
{
use Notifiable, BillableWithPaypal;

// ...

/**
* @inheritDoc
*/
protected function getShippingFields(): array
{
return [
'address' => $this->shipping_address,
'city' => $this->shipping_city,
'state' => $this->shipping_state,
'postal_code' => $this->shipping_postal_code,
'country' => $this->shipping_country
];
}
}
```

## Change log

Please see the [changelog](changelog.md) for more information on what has changed recently.

## Testing

``` bash
$ composer test
```

## Contributing

Please see [contributing.md](contributing.md) for details and a todolist.

## Security

If you discover any security related issues, please email me@cristiancosenza.com instead of using the issue tracker.

## Credits

- [Cristian Cosenza][link-author]
- [All Contributors][link-contributors]

## License

license. Please see the [license file](license.md) for more information.

[ico-version]: https://img.shields.io/packagist/v/hypnodev/larapal.svg?style=flat-square
[ico-downloads]: https://img.shields.io/packagist/dt/hypnodev/larapal.svg?style=flat-square
[ico-travis]: https://img.shields.io/travis/hypnodev/larapal/master.svg?style=flat-square
[ico-styleci]: https://styleci.io/repos/12345678/shield

[link-packagist]: https://packagist.org/packages/hypnodev/larapal
[link-downloads]: https://packagist.org/packages/hypnodev/larapal
[link-author]: https://github.com/hypnodev
[link-contributors]: ../../contributors
43 changes: 43 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "hypnodev/larapal",
"description": "An easy way to integrate Paypal into Laravel",
"license": "MIT",
"authors": [
{
"name": "Cristian Cosenza",
"email": "me@cristiancosenza.com"
}
],
"homepage": "https://github.com/hypnodev/larapal",
"keywords": ["Laravel", "Larapal"],
"require": {
"illuminate/support": "~5|~6|~7",
"paypal/paypal-checkout-sdk": "^1.0.1"
},
"require-dev": {
"phpunit/phpunit": "^8.0",
"mockery/mockery": "^1.1",
"orchestra/testbench": "~3|~4",
"sempro/phpunit-pretty-print": "^1.0"
},
"autoload": {
"psr-4": {
"hypnodev\\Larapal\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"hypnodev\\Larapal\\Tests\\": "tests"
}
},
"extra": {
"laravel": {
"providers": [
"hypnodev\\Larapal\\LarapalServiceProvider"
],
"aliases": {
"Larapal": "hypnodev\\Larapal\\Facades\\Larapal"
}
}
}
}
Loading

0 comments on commit 9b34ded

Please sign in to comment.