sfolador / heidipay-saloon
Integrate HeidiPay API in PHP with Saloon
1.1
2023-05-13 17:02 UTC
Requires
- php: ^8.1
- sammyjo20/saloon: ^2.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.9
- pestphp/pest: ^2.0
- pestphp/pest-plugin-arch: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- spatie/ray: ^1.37
This package is auto-updated.
Last update: 2024-11-09 04:24:31 UTC
README
Integrate your application with HeidiPay API using Saloon
This package provides a simple way to integrate your application with the HeidiPay API.
use Sfolador\HeidiPaySaloon\Services\HeidiPay; use Sfolador\HeidiPaySaloon\Dto\AuthDto; $apiUrl = 'https://api.heidipay.com'; $heidipay = new HeidiPay(apiUrl: $apiUrl); $authDto = AuthDto::from(merchantKey: "merchant-key"); $heidipay->auth($authDto); //The next requests will use the token returned by the `auth` API $contractResponse = $heidipay->contract($contractInitDto); // the response is a `Response` object, you can get the DTO using the `dtoOrFail` method $contractResponseDto = $contractResponse->dtoOrFail();
Installation
You can install the package via composer:
composer require sfolador/heidipay-saloon
Usage
Auth
Before calling any of the API endpoint it is necessary to authenticate with the HeidiPay API and obtain a token. Please read the official documentation at HeidiPay API for more information.
use Sfolador\HeidiPaySaloon\Services\HeidiPay; use Sfolador\HeidiPaySaloon\Dto\AuthDto; $apiUrl = 'https://sandbox-origination.heidipay.com'; //for production use $apiUrl = 'https://api.heidipay.com'; $heidipay = HeidiPay::init(apiUrl: $apiUrl); $authDto = AuthDto::from(merchantKey: "merchant-key"); // the merchant key is provided by HeidiPay $token = $heidipay->auth($authDto);
Contract init
Initialize a new contract for a user. Please read the official documentation at HeidiPay API for more information.
use Sfolador\HeidiPaySaloon\Services\HeidiPay; use Sfolador\HeidiPaySaloon\Models\Amount; use Sfolador\HeidiPaySaloon\Models\Customer; use Sfolador\HeidiPaySaloon\Models\Webhooks; use Sfolador\HeidiPaySaloon\Models\CreditInitProduct; use Sfolador\HeidiPaySaloon\Dto\ContractInitDto; $heidipay = HeidiPay::init(apiUrl: $apiUrl); $amount = new Amount( currency: 'BRL',amount: 100, amountFormat: AmountFormat::DECIMAL); $customer = new Customer( email: 'customer@example.com', title: '', firstname: 'Test', lastname: 'Test', dateOfBirth: '', contactNumber: '', companyName: '', residence: '' ); $webhooks = new Webhooks( success: 'https://www.example.com/success', failure: 'https://www.example.com/failure', cancel: 'https://www.example.com/cancel', status: 'https://www.example.com/status', mappingScheme: 'default' ); // remember to set a token for the webhooks and save it in your database to verify the webhooks later $webhooks->setToken(str()->random(32)); $products = [new CreditInitProduct( sku: null, name: 'Test', quantity: 1, price: '100', imageThumbnailUrl: null, imageOriginalUrl: null, description: null )]; $contractInitDto = new ContractInitDto($amount, $customer, $webhooks, $products); $contractResponse = $heidipay->contract($contractInitDto); // the response is a `Response` object, you can get the DTO using the `dtoOrFail` method $contractResponseDto = $contractResponse->dtoOrFail(); // $contractResponseDto will be a ContractDto object and have these properties: $contractResponseDto->action; $contractResponseDto->redirectUrl; // the url to redirect the user to complete the contract $contractResponseDto->external_contract_uuid // the contract uuid $contractResponseDto->application_uuid // the application uuid
Credits
License
The MIT License (MIT). Please see License File for more information.