Skip to content

Housekeeping #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/.gitattributes export-ignore
/.editorconfig export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/composer.lock export-ignore
/CODE_OF_CONDUCT.md export-ignore
/CONTRIBUTING.md export-ignore
/phpunit.xml.dist export-ignore
/phpunit.xml export-ignore
/phpstan.neon export-ignore
/tests export-ignore
/.github export-ignore

Expand Down
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md → .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Violating these terms may lead to a permanent ban.
### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within
Expand Down
18 changes: 13 additions & 5 deletions CONTRIBUTING.md → .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ Please be considerate towards maintainers when raising issues or presenting pull
world that developers are civilized and selfless people.

It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.
quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the
maintainer's decision, and do not be upset or abusive if your submission is not used.

## Viability

Expand All @@ -40,16 +41,23 @@ Before submitting a pull request:

If the project maintainer has any additional requirements, you will find them listed here.

- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer).
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)**
- The easiest way to apply the conventions is to
install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer).

- **Add tests!** - Your patch won't be accepted if it doesn't have tests.

- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
- **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](https://semver.org/). Randomly breaking public APIs is not an option.
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://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](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
- **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](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages)
before submitting.

**Happy coding**!
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ assignees: ''
---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
A clear and concise description of what the issue is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
name: Tests

on: [ push, pull_request ]
on:
push:
pull_request:
schedule:
- cron: '0 0 1 * *'

jobs:
test:
runs-on: ${{ matrix.os }}
timeout-minutes: 5
strategy:
fail-fast: true
matrix:
Expand All @@ -16,7 +21,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
39 changes: 16 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,18 @@
[![Total Downloads](http://poser.pugx.org/phpjuice/paypal-http-client/downloads)](https://packagist.org/packages/phpjuice/paypal-http-client)
[![License](http://poser.pugx.org/phpjuice/paypal-http-client/license)](https://packagist.org/packages/phpjuice/paypal-http-client)

This Package is a PHP Http Client. It provides a simple, fluent API to interact with PayPal rest API with both sandbox
and production environments supported.
This Package is a PHP Http Client. It provides a simple, fluent API to interact with PayPal rest API.

To learn all about it, head over to the extensive [documentation](https://phpjuice.gitbook.io/paypal-checkout-sdk).

## Installation

PayPal HTTP Client Package requires PHP 7.4 or higher.
This Package requires PHP 7.4 or higher.

> **INFO:** If you are using an older version of php this package may not function correctly.

The supported way of installing PayPal HTTP Client package is via Composer.
One can install this package via Composer.

```bash
composer require phpjuice/paypal-http-client
composer require "phpjuice/paypal-http-client"
```

## Setup
Expand All @@ -28,18 +25,19 @@ PayPal HTTP Client is designed to simplify using the new PayPal checkout api in

### Setup Credentials

Get client ID and client secret by going
to [https://developer.paypal.com/developer/applications](https://developer.paypal.com/developer/applications) and
generating a REST API app. Get Client ID and Secret from there.
Get client ID and client secret by visiting
the [PayPal Developer Account](https://developer.paypal.com/developer/applications) and
generating a REST API app.

### Setup a Paypal Client
### Setup Paypal Client

Inorder to communicate with PayPal platform we need to set up a client first :
In order to communicate with PayPal platform we need to set up a client first :

#### Create a client with sandbox environment:

```php
// import namespace
<?php

use PayPal\Http\Environment\SandboxEnvironment;
use PayPal\Http\PayPalClient;

Expand All @@ -57,7 +55,8 @@ $client = new PayPalClient($environment);
#### Create a client with production environment:

```php
// import namespace
<?php

use PayPal\Http\Environment\ProductionEnvironment;
use PayPal\Http\PayPalClient;

Expand All @@ -74,11 +73,11 @@ $client = new PayPalClient($environment);

## Changelog

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

## Contributing

Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for details and a todo list.
Please see [CONTRIBUTING](./.github/CONTRIBUTING.md) for details and a todo list.

## Security

Expand All @@ -91,10 +90,4 @@ If you discover any security related issues, please email author instead of usin

## License

license. Please see the [Licence](https://github.com/phpjuice/paypal-http-client/blob/main/LICENSE) for more
information.

![Tests](https://github.com/phpjuice/paypal-http-client/workflows/Tests/badge.svg?branch=main)
[![Latest Stable Version](http://poser.pugx.org/phpjuice/paypal-http-client/v)](https://packagist.org/packages/phpjuice/paypal-http-client)
[![Total Downloads](http://poser.pugx.org/phpjuice/paypal-http-client/downloads)](https://packagist.org/packages/phpjuice/paypal-http-client)
[![License](http://poser.pugx.org/phpjuice/paypal-http-client/license)](https://packagist.org/packages/phpjuice/paypal-http-client)
Please see the [Licence](./LICENSE) file.
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
}
],
"require": {
"php": "^7.4|^8.0|^8.1",
"php": "^7.4 || ^8.0 || ^8.1",
"ext-json": "*",
"guzzlehttp/psr7": "^1.6|^2.0",
"guzzlehttp/psr7": "^1.6 || ^2.0",
"guzzlehttp/guzzle": "^7.0"
},
"require-dev": {
Expand Down Expand Up @@ -49,6 +49,9 @@
]
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true
}
}
}
21 changes: 7 additions & 14 deletions src/AccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,22 @@ class AccessToken
{
/**
* Access token returned by PayPal.
*
* @var string
*/
protected string $token;

/**
* Access token type.
*
* @var string
*/
protected string $token_type;

/**
* time for access token to expires in seconds.
*
* @var int
* Time for access token to expires in seconds.
*/
protected int $expires_in;

/**
* time for creating access token to expires in seconds.
*
* @var int
* Time for creating access token to expires in seconds.
*/
protected int $created_at;

Expand All @@ -41,34 +34,34 @@ public function __construct(string $token, string $token_type, int $expires_in)
}

/**
* gets the token.
* Get the token.
*/
public function getToken(): ?string
{
return $this->token;
}

/**
* gets the token.
* Get the token type.
*/
public function getTokenType(): ?string
{
return $this->token_type;
}

/**
* returns authorization string.
* Returns authorization string.
*/
public function authorizationString(): string
{
return $this->token_type.' '.$this->token;
}

/**
* returns if a token is expired or not.
* Determines if the token is expired or not.
*/
public function isExpired(): bool
{
return time() >= $this->created_at + $this->expires_in;
return time() >= ($this->created_at + $this->expires_in);
}
}
9 changes: 0 additions & 9 deletions src/Environment/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,9 @@

interface Environment
{
/**
* @return string
*/
public function name(): string;

/**
* @return string
*/
public function baseUrl(): string;

/**
* @return string
*/
public function basicAuthorizationString(): string;
}
7 changes: 0 additions & 7 deletions src/Environment/PayPalEnvironment.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@ abstract class PayPalEnvironment implements Environment
{
/**
* Paypal client id.
*
* @var string
*/
protected string $clientId;

/**
* PayPal client secret.
*
* @var string
*/
protected string $clientSecret;

Expand All @@ -24,9 +20,6 @@ public function __construct(string $clientId, string $clientSecret)
$this->clientSecret = $clientSecret;
}

/**
* @return string
*/
public function basicAuthorizationString(): string
{
return base64_encode($this->clientId.':'.$this->clientSecret);
Expand Down
6 changes: 0 additions & 6 deletions src/Environment/ProductionEnvironment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,11 @@

class ProductionEnvironment extends PayPalEnvironment
{
/**
* @return string
*/
public function baseUrl(): string
{
return 'https://api.paypal.com';
}

/**
* @return string
*/
public function name(): string
{
return 'production';
Expand Down
6 changes: 0 additions & 6 deletions src/Environment/SandboxEnvironment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,11 @@

class SandboxEnvironment extends PayPalEnvironment
{
/**
* @return string
*/
public function baseUrl(): string
{
return 'https://api.sandbox.paypal.com';
}

/**
* @return string
*/
public function name(): string
{
return 'sandbox';
Expand Down
9 changes: 0 additions & 9 deletions src/Exceptions/JsonEncodingException.php

This file was deleted.

Loading