lloricode / laravel-paymaya-sdk
SDK for Paymaya using Laravel
Fund package maintenance!
lloricde
Installs: 2 338
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 4
Forks: 0
Open Issues: 0
Requires
- php: ^8.2
- ext-json: *
- illuminate/contracts: ^10.0|^11.0
- lloricode/paymaya-sdk-php: ^2.0.0
- spatie/laravel-package-tools: ^1.16.2
Requires (Dev)
- composer-runtime-api: ^2.2.2
- laravel/pint: ^1.14
- orchestra/testbench: ^8.0|^9.0
- pestphp/pest: ^2.34.1
- pestphp/pest-plugin-laravel: ^2.3
- phpstan/extension-installer: ^1.3.1
- phpstan/phpstan-deprecation-rules: ^1.1.4
- phpstan/phpstan-phpunit: ^1.3.16
- rector/rector: ^1.0.2
- spatie/laravel-ray: ^1.35.1
This package is auto-updated.
Last update: 2024-11-08 12:38:09 UTC
README
Paymaya SDK for laravel, it uses lloricode/paymaya-sdk-php.
Installation
You can install the package via composer:
composer require lloricode/laravel-paymaya-sdk
You can publish the config file with:
php artisan vendor:publish --provider="Lloricode\LaravelPaymaya\LaravelPaymayaServiceProvider" --tag="laravel-paymaya-sdk-config"
This is the contents of the published config file:
<?php use Lloricode\Paymaya\PaymayaClient; use Lloricode\Paymaya\Request\Webhook\Webhook; return [ 'mode' => env('PAYMAYA_MODE', PaymayaClient::ENVIRONMENT_SANDBOX), 'keys' => [ 'public' => env('PAYMAYA_PUBLIC_KEY'), 'secret' => env('PAYMAYA_SECRET_KEY'), ], /** * * Webhooks * */ 'webhooks' => [ Webhook::CHECKOUT_SUCCESS => 'api/payment-callback/paymaya/success', Webhook::CHECKOUT_FAILURE => 'api/payment-callback/paymaya/failure', Webhook::CHECKOUT_DROPOUT => 'api/payment-callback/paymaya/dropout', // Webhook::PAYMENT_SUCCESS => 'api/test/success', // Webhook::PAYMENT_EXPIRED => 'api/test/expired', // Webhook::PAYMENT_FAILED => 'api/test/failed', ], 'checkout' => [ 'customization' => [ 'logoUrl' => 'https://image1.png', 'iconUrl' => 'https://image2.png', 'appleTouchIconUrl' => 'https://image3.png', 'customTitle' => 'test paymaya sandbox title', 'colorScheme' => '#e01c44', 'redirectTimer'=> 3, ], ], ];
Usage
You can copy the sample to test it.
Checkout
https://developers.paymaya.com/blog/entry/paymaya-checkout-api-overview
use Carbon\Carbon; use Lloricode\Paymaya\Request\Checkout\Amount\AmountDetail; use Lloricode\Paymaya\Request\Checkout\Amount\Amount; use Lloricode\Paymaya\Request\Checkout\Buyer\BillingAddress; use Lloricode\Paymaya\Request\Checkout\Buyer\Buyer; use Lloricode\Paymaya\Request\Checkout\Buyer\Contact; use Lloricode\Paymaya\Request\Checkout\Buyer\ShippingAddress; use Lloricode\Paymaya\Request\Checkout\Checkout; use Lloricode\Paymaya\Request\Checkout\Item; use Lloricode\Paymaya\Request\Checkout\MetaData; use Lloricode\Paymaya\Request\Checkout\RedirectUrl; use Lloricode\Paymaya\Request\Checkout\TotalAmount; use PaymayaSDK; $checkout = (new Checkout()) ->setTotalAmount( (new TotalAmount()) ->setValue(100) ->setDetails( (new AmountDetail()) ->setSubtotal(100) ) ) ->setBuyer( (new Buyer()) ->setFirstName('John') ->setMiddleName('Paul') ->setLastName('Doe') ->setBirthday(Carbon::parse('1995-10-24')) ->setCustomerSince(Carbon::parse('1995-10-24')) ->setGender('M') ->setContact( (new Contact()) ->setPhone('+639181008888') ->setEmail('merchant@merchantsite.com') ) ->setShippingAddress( (new ShippingAddress()) ->setFirstName('John') ->setMiddleName('Paul') ->setLastName('Doe') ->setPhone('+639181008888') ->setEmail('merchant@merchantsite.com') ->setLine1('6F Launchpad') ->setLine2('Reliance Street') ->setCity('Mandaluyong City') ->setState('Metro Manila') ->setZipCode('1552') ->setCountryCode('PH') ->setShippingType('ST') ) ->setBillingAddress( (new BillingAddress()) ->setLine1('6F Launchpad') ->setLine2('Reliance Street') ->setCity('Mandaluyong City') ->setState('Metro Manila') ->setZipCode('1552') ->setCountryCode('PH') ) ) ->addItem( (new Item()) ->setName('Canvas Slip Ons') ->setQuantity(1) ->setCode('CVG-096732') ->setDescription('Shoes') ->setAmount( (new Amount()) ->setValue(100) ->setDetails( (new AmountDetail()) ->setDiscount(0) ->setServiceCharge(0) ->setShippingFee(0) ->setTax(0) ->setSubtotal(100) ) ) ->setTotalAmount( (new Amount()) ->setValue(100) ->setDetails( (new AmountDetail()) ->setDiscount(0) ->setServiceCharge(0) ->setShippingFee(0) ->setTax(0) ->setSubtotal(100) ) ) ) ->setRedirectUrl( (new RedirectUrl()) ->setSuccess('https://www.merchantsite.com/success') ->setFailure('https://www.merchantsite.com/failure') ->setCancel('https://www.merchantsite.com/cancel') )->setRequestReferenceNumber('1551191039') ->setMetadata( (new MetaData()) ->setSMI('smi') ->setSMN('smn') ->setMCI('mci') ->setMPC('mpc') ->setMCO('mco') ->setMST('mst') ); $checkoutResponse = PaymayaSDK::checkout()->execute($checkout); echo 'id: '.$checkoutResponse->checkoutId."\n"; echo 'url: '.$checkoutResponse->redirectUrl."\n";
Webhook
# see config `paymaya-sdk.webhooks` array to set your webhooks,
# then run this to register webhooks.
php artisan paymaya-sdk:webhook:register
# retrieve webhooks
php artisan paymaya-sdk:webhook:retrieve
# retrieve output
+--------+------------------+------------------------------+---------------------+---------------------+
| id | name | callbackUrl | createdAt | updatedAt |
+--------+------------------+------------------------------+---------------------+---------------------+
| <uuid> | CHECKOUT_SUCCESS | http://localhost/api/success | 2021-02-05 17:40:40 | 2021-02-05 17:40:40 |
| <uuid> | CHECKOUT_FAILURE | http://localhost/api/failed | 2021-02-05 17:40:45 | 2021-02-05 17:40:45 |
| <uuid> | CHECKOUT_DROPOUT | http://localhost/api/dropout | 2021-02-05 17:40:45 | 2021-02-05 17:40:45 |
+--------+------------------+------------------------------+---------------------+---------------------+
Testing with Guzzle Mock
Add this to your Base Test Case
use GuzzleHttp\Handler\MockHandler; use GuzzleHttp\HandlerStack; use GuzzleHttp\Psr7\Response; use PaymayaSDK; protected function fakePaymaya(array $mockResponse, &$history = []) { $mock = []; foreach ($mockResponse as $value) { $mock[] = new Response( $value['status'] ?? 200, $value['headers'] ?? [], json_encode($value['body'] ?? []), ); } PaymayaSDK::client()->setHandlerStack( HandlerStack::create(new MockHandler($mock)), $history ); }
Sample usage of mock
/** * @test */ public function success_checkout() { $paymayaID = 'test-paymaya-generated-id'; $paymayaRedirectUrl = 'http://test-paymaya/redirect-url'; $this->fakePaymaya( [ [ 'body' => [ 'checkoutId' => $paymayaID, 'redirectUrl' => $paymayaRedirectUrl, ], ], ] ); // you test
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.