Git Product home page Git Product logo

laravel-paymongo's Introduction

Paymongo for Laravel

Run tests Quality Score Latest Stable Version Total Downloads Monthly Downloads Daily Downloads License

A PHP Library for Paymongo.

This package is not affiliated with Paymongo. The package requires PHP 7.2+

Documentation

https://paymongo.rigelkentcarbonel.com

Todo

  • Add unit test for the BaseModel.
  • Fix the magic method when accessing a nested data with underscore ("_").
  • Add artisan commands for adding, enabling, and disabling webhooks.
  • Fix the test case for the PaymongoValidateSignature middleware.
  • Transfer from travis to github actions.
  • Refactor test cases into Pest.

Laravel Version Compatibility

Laravel Package
5.8.x 1.x
6.x.x 1.x
7.x.x 1.x
8.x.x 2.x

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Made with โค๏ธ by Rigel Kent Carbonel

laravel-paymongo's People

Contributors

abenojardev avatar chrisbjr avatar dependabot[bot] avatar flyajar avatar gringiemarfelix avatar laravel-shift avatar lloricode avatar luigel avatar rdaitan-cp avatar rigelevotech avatar stylecibot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-paymongo's Issues

Paymongo Error when passing a tenth or hundredth decimal in amount argument

Prerequisites

  • Are you using Laravel 6 and above?
  • Able to reproduce the behaviour outside of your code, the problem is isolated to Laravel Paymongo.
  • Checked that your issue isn't already filed.
  • Checked if no PR was submitted that fixes this problem.
  • Filled in the entire issue template

Versions

  • PHP version:
    PHP 7.3.8 (cli) (built: Aug 11 2019 20:50:16) ( NTS )
    Copyright (c) 1997-2018 The PHP Group
    Zend Engine v3.3.8, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.8, Copyright (c) 1999-2018, by Zend Technologies
    with Xdebug v2.7.2, Copyright (c) 2002-2019, by Derick Rethans

  • Laravel version:
    Laravel Framework 7.28.3

  • Package version:
    luigel/laravel-paymongo : ^1.3.1

Description

Paymongo only accepts integer in the argument amount,

looking at the package, we have a method there convertPayloadAmountsToInteger($payload)
that converts the passed amount from app to package class. 
   
In the app we are developing, our products price are in hundredth decimal (P 112.529) 
Passing this in Paymongo::paymentIntent->create([]), returns a paymongo exception
"amount should be an integer"  

Steps to Reproduce

1. Please create a file tests/AmounToIntegerTest.php
2. Copy this code into tests/AmounToIntegerTest.php

    <?php

		namespace Luigel\Paymongo\Tests;

		use Luigel\Paymongo\Models\BaseModel;
		use Luigel\Paymongo\Traits\Request;

		class AmounToIntegerTest extends BaseTestCase
		{
		    use Request; 

		    /** @test */
		    public function it_can_convert_without_decimal()
		    { 
		    	$payload = [
		    		'amount' => 147
		    	];

		    	$convertedPayload = $this->convertPayloadAmountsToInteger($payload);

		        $this->assertIsInt($convertedPayload['amount']);  
		        $this->assertIsNotFloat($convertedPayload['amount']);
		    }

		    /** @test */
		    public function it_can_convert_with_in_tenth_decimal()
		    { 
		    	$payload = [
		    		'amount' => 147.95
		    	];

		    	$convertedPayload = $this->convertPayloadAmountsToInteger($payload);

		        $this->assertIsInt($convertedPayload['amount']); 
		        $this->assertIsNotFloat($convertedPayload['amount']);
		    }

		    /** @test */
		    public function it_can_convert_with_in_hundredth_decimal()
		    { 
		    	$payload = [
		    		'amount' => 254.950
		    	];

		    	$convertedPayload = $this->convertPayloadAmountsToInteger($payload);

		        $this->assertIsInt($convertedPayload['amount']); 
		        $this->assertIsNotFloat($convertedPayload['amount']);
		    }
		}  

3. composer test 

There were 2 failures:

1) Luigel\Paymongo\Tests\AmounToIntegerTest::it_can_convert_with_in_tenth_decimal
Failed asserting that 14794.999999999998 is of type "int".

/Users/macbook/Documents/Docker/nutriasia/laravel-paymongo/tests/AmounToIntegerTest.php:34

2) Luigel\Paymongo\Tests\AmounToIntegerTest::it_can_convert_with_in_hundredth_decimal
Failed asserting that 25495.0 is of type "int".

/Users/macbook/Documents/Docker/nutriasia/laravel-paymongo/tests/AmounToIntegerTest.php:47

FAILURES!
Tests: 3, Assertions: 4, Failures: 2.

Expected behavior:

Assuming we have 
	147.95 
	should return 14795

	254.950
	should return 25495

Actual behavior:

Assuming we have 
	147 
	convertPayloadAmountsToInteger() will return it as 14700
	this is integer (correct)

	147.95 
	convertPayloadAmountsToInteger() will return it as 14794.999999999998
	this is not an integer (error)

	254.950
	convertPayloadAmountsToInteger() will return it as 25495.0
	this is not an integer (error)

Additional Information

    none

PaymentIntent create method returns null

I used the code below to test the payment intent but it returns null when I used dd($paymentIntent);

PaymentMethod is working but the paymentintent create method is not working on my end.

$paymentIntent = Paymongo::paymentIntent()->create([
            'amount' => 10000,
            'payment_method_allowed' => [
                'card'
            ],
            'payment_method_options' => [
                'card' => [
                    'request_three_d_secure' => 'automatic'
                ]
            ],
            'description' => 'This is a test payment intent',
            'statement_descriptor' => 'LUIGEL STORE',
            'currency' => "PHP"
        ]);

dd($paymentIntent); 

Note:

  • Paymongo api key is already in .env
  • I'm using api key test
  • Im using Laravel 7
  • Paymongo Account is activated

[Documentation Issue] Amount Conversion to integer

Please add documentation on the amount value conversion used by the package.
The function convertPayloadAmountsToInteger conflicts a little bit with PayMongo's documentation.

PayMongo's documentation says that the amount value should be an integer.
However, this package's code does the conversion to integer automatically.

Here are my suggestions for this issue. Kindly check which works best

  1. maybe add new config in config/paymongo.php so that devs can decide to use the package's own conversion or not.
  2. use 'amount' => 100.50', in the example code in the documentation (reference: https://paymongo.rigelkentcarbonel.com/payment-intents#sample-2). However, I think the package might still conflict with other PHP packages like moneyphp/money (which I'm currently using)
  3. follow PayMongo's convention,

Thank you!

[BUG] 500 internal error

Server error: POST https://api.paymongo.com/v1/sources/` resulted in a 500 Internal Server Error response: {"errors":[{"detail":"Something went wrong on our end. We have been notified and will be investigating. Trust us, these (truncated...)`

Hi, your library is great, but I'm facing an issue when using grab_pay and gcash as payment. This occur after a success request then redirect to their checkout_url, I tried to follow their documentation just to check if it's working well in their end, but it also giving the same error response. I know this is not your bug, I'm just letting you know lol

[BUG] Getting list of webhooks returns the array but the data is empty

Prerequisites

  • Are you using Laravel 6 and above?
  • Able to reproduce the behaviour outside of your code, the problem is isolated to Laravel Paymongo.
  • Checked that your issue isn't already filed.
  • Checked if no PR was submitted that fixes this problem.
  • Filled in the entire issue template

Versions

  • PHP version:
  • Laravel version:
  • Package version:

Description

Steps to Reproduce

Expected behavior:

Actual behavior:

Additional Information

Any additional information, configuration or data that might be necessary to reproduce the issue.

[BUG]

Prerequisites

  • Are you using Laravel 6 and above?
  • Able to reproduce the behaviour outside of your code, the problem is isolated to Laravel Paymongo.
  • Checked that your issue isn't already filed.
  • Checked if no PR was submitted that fixes this problem.
  • Filled in the entire issue template

Versions

  • PHP version: 8.0.27
  • Laravel version: 8.83.27
  • Package version: 2.4.0

Description

Steps to Reproduce

Note that I am receiving the json payload from paymongo with no error.

However when I am trying to use middlewares for my webhooks specifically for payment.paid and payment.failed events, I am still receiving the json payload but then after that there's an error in the logs. So I am not sure if it is validating the signature properly.

Expected behavior:
Receving the json payload from paymongo with no error.

Actual behavior:
Receiving an error message in the logs:

Luigel\Paymongo\Middlewares\PaymongoValidateSignature::handle(): Return value must be of type ?Illuminate\Http\Response, Illuminate\Http\JsonResponse returned {"exception":"[object] (TypeError(code: 0): Luigel\\Paymongo\\Middlewares\\PaymongoValidateSignature::handle(): Return value must be of type ?Illuminate\\Http\\Response, Illuminate\\Http\\JsonResponse returned at /home/vagrant/code/web/others/laravel/booking-laravel-filament/vendor/luigel/laravel-paymongo/src/Middlewares/PaymongoValidateSignature.php:27)

[BUG] Implement 3D Secure using this library?

Prerequisites

  • Are you using Laravel 6 and above?
  • Able to reproduce the behaviour outside of your code, the problem is isolated to Laravel Paymongo.
  • Checked that your issue isn't already filed.
  • Checked if no PR was submitted that fixes this problem.
  • Filled in the entire issue template

Versions

  • PHP version:
  • Laravel version:
  • Package version:

Description

Steps to Reproduce

Expected behavior:

Actual behavior:

Additional Information

Any additional information, configuration or data that might be necessary to reproduce the issue.

Gcash Supported?

Is this gcash supported? because many are gcash user here in philippines

[BUG] Executing Cancel Payment Intent produces a BadRequest error exception

Prerequisites

  • Are you using Laravel 6 and above?
  • Able to reproduce the behaviour outside of your code, the problem is isolated to Laravel Paymongo.
  • Checked that your issue isn't already filed.
  • Checked if no PR was submitted that fixes this problem.
  • Filled in the entire issue template

Versions

  • PHP version: 7.3.17
  • Laravel version: 6.13.1
  • Package version: v1.1.2

Description

Cancelling a Payment Intent throws an error exception of BadRequestException:

 "message": "Payment intent with id pi_BRbuVgVdZpGar5EjzSSf1ce7 has succeeded.",
    "exception": "Luigel\\Paymongo\\Exceptions\\BadRequestException",
    "file": "/var/www/sample/vendor/luigel/laravel-paymongo/src/Traits/Request.php",
    "line": 220,
    "trace": [
        {
            "file": "/var/www/sample/vendor/luigel/laravel-paymongo/src/Traits/Request.php",
            "line": 171,
            "function": "request",
            "class": "Luigel\\Paymongo\\Paymongo",
            "type": "->"
        },
        {
            "file": "/var/www/sample/vendor/luigel/laravel-paymongo/src/Models/PaymentIntent.php",
            "line": 148,
            "function": "cancel",
            "class": "Luigel\\Paymongo\\Paymongo",
            "type": "->"
        }

Steps to Reproduce

  1. Create a Payment Intent.
  2. Get the Payment Intent ID you have created.
  3. Cancel the Payment Intent with the provided Payment Intent ID.

Expected behavior:

Payment Intent should be cancelled successfully.

Actual behavior:

Produces a BadRequestException error.

Additional Information

Checking on PayMongo's API documentation, I don't see a way of cancelling Payment Intents. Maybe it was removed? I could only see creating, fetching, and attaching it to a Payment Method.

Also trying to access the endpoint URL gives 404/blank page:

https://api.paymongo.com/v1/payment_intents/pi_BRbuVgVdZpGar5EjzSSf1ce7/cancel

The cancel endpoint for Payment Intents might have been removed.

[BUG]PHP 8 Support

Prerequisites

  • Are you using Laravel 6 and above?
  • Able to reproduce the behaviour outside of your code, the problem is isolated to Laravel Paymongo.
  • Checked that your issue isn't already filed.
  • Checked if no PR was submitted that fixes this problem.
  • Filled in the entire issue template

Versions

  • PHP version: 8.1
  • Laravel version: 8
  • Package version: v1.5.0

Description

Steps to Reproduce

Expected behavior:

Actual behavior:

Additional Information

Any additional information, configuration or data that might be necessary to reproduce the issue.

Gcash Payment help

Do I need to create a webhook or i can just directly use this?

$gcashSource = Paymongo::source()->create([
    		'type' => 'gcash',
    		'amount' => 100.00,
    		'currency' => 'PHP',
    		'redirect' => [
    			'success' => 'http://localhost:8000/success',
    			'failed' => 'http://localhost:8000/failed'
    		]
    	]);

actually i didn't understand when to use webhook

[BUG] syntax error, unexpected ')' in Traits/HasCommandValidation.php:14

Prerequisites

  • Are you using Laravel 6 and above?
  • Able to reproduce the behaviour outside of your code, the problem is isolated to Laravel Paymongo.
  • Checked that your issue isn't already filed.
  • Checked if no PR was submitted that fixes this problem.
  • Filled in the entire issue template

Versions

  • PHP version: 7.2
  • Laravel version: 7
  • Package version: Latest

Description

    $validator = Validator::make(
        $data,
        $rules, <--- remove comma here
    );

Steps to Reproduce

Expected behavior:

Actual behavior:

Additional Information

Any additional information, configuration or data that might be necessary to reproduce the issue.

Laravel Testing Mocking

How to mock this function?

 Paymongo::source()->create([
            'type' => 'gcash',
            'amount' => 100,
            'currency' => 'PHP',
            'redirect' => [
                'success' => 'http://localhost/success',
                'failed' => 'http://localhost/failed'
            ]
        ])

in my test file

Paymongo::shouldReceive('source')
            ->shouldReceive('create')
            ->andReturn(json_decode('
            {
                "data": {
                    "id": "gg",
                    "type": "source",
                    "attributes": {
                        "amount": 10000,
                        "billing": null,
                        "currency": "PHP",
                        "description": null,
                        "livemode": false,
                        "redirect": {
                            "checkout_url": "https://test-sources.paymongo.com/sources?id=gg",
                            "failed": "http://localhost/failed",
                            "success": "http://localhost/success"
                            },
                        "statement_descriptor": null,
                        "status": "pending",
                        "type": "gcash",
                        "created_at": 1648140991,
                        "updated_at": 1648140991
                    }
                }
            }',true));

but i got this error Call to a member function create() on null

Add Error Handling Support for Custom Message or Attribute [IDEA]

Prerequisites

Versions

  • PHP version: 7.3
  • Laravel version: 8.11
  • Package version: 1.2

Description

I want to customize the error callback attribute or message.

Example

  • details.card_number format is invalid
    this is generated in the package by using try catch.
    is this possible to make this work like the default laravel validation? that it would return a validation exception.

Additional Information

Any additional information, configuration or data that might be needed to understand the proposal.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.