lloricode / paymaya-sdk-php
Paymaya SDK for PHP
Fund package maintenance!
lloricode
Installs: 5 043
Dependents: 1
Suggesters: 0
Security: 0
Stars: 4
Watchers: 3
Forks: 0
Open Issues: 1
Requires
- php: ^8.0
- ext-json: *
- guzzlehttp/guzzle: ^7.5
Requires (Dev)
- composer-runtime-api: ^2.2.2
- laravel/pint: ^1.5
- mockery/mockery: ^1.4
- pestphp/pest: ^1.22
- phly/keep-a-changelog: ^2.11
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- rector/rector: ^0.15.16
- spatie/ray: ^1.36
- spatie/x-ray: ^1.1
This package is auto-updated.
Last update: 2024-11-18 15:15:40 UTC
README
Paymaya SDK for PHP
Paymaya SDK for PHP.
Installation
You can install the package via composer:
composer require lloricode/paymaya-sdk-php
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\Client\Checkout\CheckoutClient; use Lloricode\Paymaya\PaymayaClient; 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; $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 = (new CheckoutClient( new PaymayaClient( 'sk-X8qolYjy62kIzEbr0QRK1h4b4KDVHaNcwMYk39jInSl', // secret 'pk-Z0OSzLvIcOI2UIvDhdTGVVfRSSeiGStnceqwUE7n0Ah', // public PaymayaClient::ENVIRONMENT_SANDBOX ) ))->execute($checkout); echo 'id: '.$checkoutResponse->checkoutId."\n"; echo 'url: '.$checkoutResponse->redirectUrl."\n";
Customization
register
use Lloricode\Paymaya\Client\Checkout\CustomizationClient; use Lloricode\Paymaya\Request\Checkout\Customization\Customization; use Lloricode\Paymaya\PaymayaClient; $customization = (new CustomizationClient( new PaymayaClient( 'sk-X8qolYjy62kIzEbr0QRK1h4b4KDVHaNcwMYk39jInSl', // secret 'pk-Z0OSzLvIcOI2UIvDhdTGVVfRSSeiGStnceqwUE7n0Ah', // public PaymayaClient::ENVIRONMENT_SANDBOX ) )) ->register( (new Customization()) ->setLogoUrl('https://image-logo.png') ->setIconUrl('https://image-icon.png') ->setAppleTouchIconUrl('https://image-apple.png') ->setCustomTitle('Test Title Mock') ->setColorScheme('#e01c44') ); echo $customization->customTitle; //check all properties in class
retrieve
use Lloricode\Paymaya\Client\Checkout\CustomizationClient; use Lloricode\Paymaya\Request\Checkout\Customization\Customization; use Lloricode\Paymaya\PaymayaClient; $customization = (new CustomizationClient( new PaymayaClient( 'sk-X8qolYjy62kIzEbr0QRK1h4b4KDVHaNcwMYk39jInSl', // secret 'pk-Z0OSzLvIcOI2UIvDhdTGVVfRSSeiGStnceqwUE7n0Ah', // public PaymayaClient::ENVIRONMENT_SANDBOX ) )) ->retrieve(); echo $customization->customTitle; //check all properties in class
delete
use Lloricode\Paymaya\Client\Checkout\CustomizationClient; use Lloricode\Paymaya\Request\Checkout\Customization\Customization; use Lloricode\Paymaya\PaymayaClient; (new CustomizationClient( new PaymayaClient( 'sk-X8qolYjy62kIzEbr0QRK1h4b4KDVHaNcwMYk39jInSl', // secret 'pk-Z0OSzLvIcOI2UIvDhdTGVVfRSSeiGStnceqwUE7n0Ah', // public PaymayaClient::ENVIRONMENT_SANDBOX ) )) ->delete();
Webhook
Checkout Webhook
use Lloricode\Paymaya\Client\Checkout\WebhookClient; use Lloricode\Paymaya\PaymayaClient; use Lloricode\Paymaya\Request\Checkout\Webhook; $paymayaClient = new PaymayaClient( 'sk-X8qolYjy62kIzEbr0QRK1h4b4KDVHaNcwMYk39jInSl', // secret 'pk-Z0OSzLvIcOI2UIvDhdTGVVfRSSeiGStnceqwUE7n0Ah', // public PaymayaClient::ENVIRONMENT_SANDBOX ); (new WebhookClient($paymayaClient))->deleteAll(); // create (new WebhookClient($paymayaClient)) ->register( (new Webhook()) ->setName(Webhook::CHECKOUT_SUCCESS) ->setCallbackUrl('https://web.test/test/success') ); (new WebhookClient($paymayaClient)) ->register( (new Webhook()) ->setName(Webhook::CHECKOUT_FAILURE) ->setCallbackUrl('https://web.test/test/failure') ); (new WebhookClient($paymayaClient)) ->register( (new Webhook()) ->setName(Webhook::CHECKOUT_DROPOUT) ->setCallbackUrl('https://web.test/test/drop') ); $webhookResponses = (new WebhookClient($paymayaClient)) ->retrieve(); // update (new WebhookClient($paymayaClient)) ->update( $webhookResponses[Webhook::CHECKOUT_SUCCESS] ->setCallbackUrl('https://web.test/test/update-success') ); // single delete (new WebhookClient($paymayaClient)) ->delete( $webhookResponses[Webhook::CHECKOUT_DROPOUT] ); // delete all (new WebhookClient($paymayaClient)) ->deleteAll();
Testing
vendor/bin/phpunit
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.