Skip to content

Commit

Permalink
Handle exception exrrors (#14)
Browse files Browse the repository at this point in the history
* Change on paymob fake request helper

* Add Item by one function

* Apply fixes from StyleCI

* Add PaymobOrderTest class for order paymob unit test

* Apply fixes from StyleCI

* Add nunomaduro/collision package

* Add Invalid Credentials Exception

* Refactor define Environment in test case class

* Add CONTRIBUTING md

* Apply fixes from StyleCI

* Update README

* Change purchase return type

* Handle errors in paymob payment

* Refactor paymob test case with excepted exception

* Apply fixes from StyleCI

* Handel errors in get order data from paymobb #12

* Fix paymob installment test case

* Apply fixes from StyleCI

* Add handle error payment method test case

* Test if customer details is not set

* Apply fixes from StyleCI (#18)

Co-authored-by: StyleCI Bot <[email protected]>

* Change handle error test to paymob handle error

* Add isSuccess of payment status

Co-authored-by: StyleCI Bot <[email protected]>
  • Loading branch information
shabayekdes and StyleCIBot authored Jan 15, 2022
1 parent facac66 commit f7ccb9d
Show file tree
Hide file tree
Showing 15 changed files with 737 additions and 281 deletions.
31 changes: 31 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Contributing

Contributions are welcome, and are accepted via pull requests. Please review these guidelines before submitting any pull requests.

## Guidelines

* Please follow the [PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md).
* Ensure that the current tests pass, and if you've added something new, add the tests where relevant.
* Remember that we follow [SemVer](http://semver.org). If you are changing the behaviour, or the public api, you may need to update the docs.
* Send a coherent commit history, making sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash](http://git-scm.com/book/en/Git-Tools-Rewriting-History) them before submitting.
* You may also need to [rebase](http://git-scm.com/book/en/Git-Branching-Rebasing) to avoid merge conflicts.

## Running Tests

You will need an install of [Composer](https://getcomposer.org) before continuing.

First, install the dependencies:

```bash
$ composer install
```

Then run phpunit:

```bash
$ vendor/bin/phpunit
```

If the test suite passes on your local machine you should be good to go.

When you make a pull request, the tests will automatically be run again by [Github Actions](https://github.com/shabayekdes/laravel-payment/actions) on multiple php versions and hhvm.
40 changes: 33 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Laravel Payment Methods
[![Build Status](https://github.styleci.io/repos/421966331/shield?style=flat&branch=develop)](https://github.styleci.io/repos/421966331) [![Packagist version](https://img.shields.io/packagist/v/shabayek/laravel-payment)](https://packagist.org/packages/shabayek/laravel-payment) [![mit](https://img.shields.io/apm/l/laravel)](https://packagist.org/packages/shabayek/laravel-payment) ![Packagist PHP Version Support](https://img.shields.io/packagist/php-v/shabayek/laravel-payment) ![Packagist Downloads](https://img.shields.io/packagist/dt/shabayek/laravel-payment)
[![Github Status](https://github.com/shabayekdes/laravel-payment/actions/workflows/tests.yml/badge.svg)](https://github.com/shabayekdes/laravel-payment/actions) [![Styleci Status](https://github.styleci.io/repos/421966331/shield?style=flat&branch=develop)](https://github.styleci.io/repos/421966331) [![Packagist version](https://img.shields.io/packagist/v/shabayek/laravel-payment)](https://packagist.org/packages/shabayek/laravel-payment) [![mit](https://img.shields.io/apm/l/laravel)](https://packagist.org/packages/shabayek/laravel-payment) ![Packagist PHP Version Support](https://img.shields.io/packagist/php-v/shabayek/laravel-payment) ![Packagist Downloads](https://img.shields.io/packagist/dt/shabayek/laravel-payment)

This is a Laravel Package for Payment Gateway Integration. It has a clear and consistent API, is fully unit tested, and even comes with an example application to get you started.

Expand Down Expand Up @@ -109,12 +109,28 @@ $payment = Payment::store($method_id);

- Add items with loop array of data items
```php
$payment->items([
"name" => "ASC1515",
"amount_cents" => "500000",
"description" => "Smart Watch",
"quantity" => "1"
]);
$items = [
[
"name" => "item1",
"price" => 100,
"quantity" => 2,
"description" => "item1 description",
],
[
"name" => "item2",
"price" => 200,
"quantity" => 1,
"description" => "item2 description",
],
];
$payment->items($items);
// OR By One
$name = "item1";
$price = 100;
$quantity = 2; // Default 1
$description = "item1 description"; // Default null

$payment->addItem($name, $price, $quantity, $description);
```

- Check the payment is online to get pay url
Expand All @@ -125,6 +141,13 @@ if ($payment->isOnline()) {
}
```

-Print the errors messages

```php
$payment->getErrors();
$payment->isSuccess();
```

- When callback from payment gateway, you can use the following code to verify the payment

```php
Expand All @@ -144,6 +167,9 @@ $method_id = 1; // payment method id from the config file
$payment_order_id = 111; // payment order id
$payment_status = Payment::store($method_id)->verify($payment_order_id);
```

## Change log
Please see [CHANGELOG](https://github.com/shabayekdes/laravel-payment/blob/main/CHANGELOG.md) for more information on what has been changed recently.
## License

The Laravel payment methods package is open-sourced software licensed under the [MIT license](https://github.com/shabayekdes/laravel-payment/blob/main/LICENSE).
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"illuminate/contracts": "^8.0"
},
"require-dev": {
"nunomaduro/collision": "^5.10",
"orchestra/testbench": "^6.0",
"phpunit/phpunit": "^9.5"
},
Expand Down
213 changes: 212 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Contracts/PaymentMethodContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ interface PaymentMethodContract
/**
* Purchase with paymant mwthod and get redirect url.
*
* @return string
* @return string|null
*/
public function purchase(): string;
public function purchase();

/**
* Pay with payment method.
Expand Down
16 changes: 3 additions & 13 deletions src/Drivers/CodMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,14 @@

class CodMethod extends Method implements PaymentMethodContract
{
/**
* Set credentials of payment methods.
*
* @return void
*/
protected function setCredentials($credentials)
{
// Implementation set credentials of payment methods.
}

/**
* Purchase with paymant mwthod and get redirect url.
*
* @return string
* @return string|null
*/
public function purchase(): string
public function purchase()
{
return '';
return null;
}

/**
Expand Down
Loading

0 comments on commit f7ccb9d

Please sign in to comment.