定制 lloricode/laravel-maya-sdk 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lloricode/laravel-maya-sdk

最新稳定版本:v3.2.0

Composer 安装命令:

composer require lloricode/laravel-maya-sdk

包简介

SDK for Paymaya using Laravel

README 文档

README

Latest Version on Packagist Tests Total Downloads codecov Donate

ko-fi

Maya SDK for laravel, it uses lloricode/paymaya-sdk-php.

Installation

You can install the package via composer:

composer require lloricode/laravel-maya-sdk

You can publish the config file with:

php artisan vendor:publish --provider="Lloricode\LaravelPaymaya\LaravelPaymayaServiceProvider" --tag="maya-sdk-config"

This is the contents of the published config file:

<?php

declare(strict_types=1);

use Lloricode\Paymaya\Enums\Environment;
use Lloricode\Paymaya\Enums\Webhook;

/**
 * @todo: Manage Exception using laravel logs, allow set config log files
 */

return [
    'mode' => env('MAYA_MODE', Environment::Sandbox->value),
    'keys' => [
        'public' => env('MAYA_PUBLIC_KEY'),
        'secret' => env('MAYA_SECRET_KEY'),
    ],

    /**
     * Webhooks
     */
    'webhooks' => [
        Webhook::CHECKOUT_SUCCESS => 'api/payment-callback/maya/success',
        Webhook::CHECKOUT_FAILURE => 'api/payment-callback/maya/failure',
        Webhook::CHECKOUT_DROPOUT => 'api/payment-callback/maya/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 maya sandbox title',
            'colorScheme' => '#e01c44',
            'redirectTimer' => 3,
            //            'hideReceiptInput' => true,
            //            'skipResultPage' => false,
            //            'showMerchantName' => true,
        ],
    ],
];

Usage

You can copy the sample to test it.

Checkout

https://developers.maya.ph/reference/createv1checkout

use Lloricode\LaravelPaymaya\Facades\PaymayaFacade;
use Lloricode\Paymaya\DataTransferObjects\Checkout\Amount\AmountDetailDto;
use Lloricode\Paymaya\DataTransferObjects\Checkout\Amount\AmountDto;
use Lloricode\Paymaya\DataTransferObjects\Checkout\Buyer\BillingAddressDto;
use Lloricode\Paymaya\DataTransferObjects\Checkout\Buyer\BuyerDto;
use Lloricode\Paymaya\DataTransferObjects\Checkout\Buyer\ContactDto;
use Lloricode\Paymaya\DataTransferObjects\Checkout\Buyer\ShippingAddressDto;
use Lloricode\Paymaya\DataTransferObjects\Checkout\CheckoutDto;
use Lloricode\Paymaya\DataTransferObjects\Checkout\ItemDto;
use Lloricode\Paymaya\DataTransferObjects\Checkout\MetaDataDto;
use Lloricode\Paymaya\DataTransferObjects\Checkout\RedirectUrlDto;
use Lloricode\Paymaya\DataTransferObjects\Checkout\TotalAmountDto;

$checkout = new CheckoutDto(
    totalAmount: new TotalAmountDto(
        value: 100,
        details: new AmountDetailDto(
            subtotal: 100
        )
    ),
    buyer: new BuyerDto(
        firstName: 'John',
        middleName: 'Paul',
        lastName: 'Doe',
        birthday: '1995-10-24',
        customerSince: '1995-10-24',
        gender: 'M',
        contact: new ContactDto(
            phone: '+639181008888',
            email: 'merchant@merchantsite.com'
        ),
        shippingAddress: new ShippingAddressDto(
            firstName: 'John',
            middleName: 'Paul',
            lastName: 'Doe',
            phone: '+639181008888',
            email: 'merchant@merchantsite.com',
            line1: '6F Launchpad',
            line2: 'Reliance Street',
            city: 'Mandaluyong City',
            state: 'Metro Manila',
            zipCode: '1552',
            countryCode: 'PH',
            shippingType: 'ST'
        ),
        billingAddress: new BillingAddressDto(
            line1: '6F Launchpad',
            line2: 'Reliance Street',
            city: 'Mandaluyong City',
            state: 'Metro Manila',
            zipCode: '1552',
            countryCode: 'PH'
        )
    ),
    items: [
        new ItemDto(
            name: 'Canvas Slip Ons',
            quantity: 1,
            code: 'CVG-096732',
            description: 'Shoes',
            amount: new AmountDto(
                value: 100,
                details: new AmountDetailDto(
                    discount: 0,
                    serviceCharge: 0,
                    shippingFee: 0,
                    tax: 0,
                    subtotal: 100
                )
            ),
            totalAmount: new AmountDto(
                value: 100,
                details: new AmountDetailDto(
                    discount: 0,
                    serviceCharge: 0,
                    shippingFee: 0,
                    tax: 0,
                    subtotal: 100
                )
            )
        ),
    ],
    redirectUrl: new RedirectUrlDto(
        success: 'https://www.merchantsite.com/success',
        failure: 'https://www.merchantsite.com/failure',
        cancel: 'https://www.merchantsite.com/cancel'
    ),
    requestReferenceNumber: '1551191039',
    metadata: new MetaDataDto(
        smi: 'smi',
        smn: 'smn',
        mci: 'mci',
        mpc: 'mpc',
        mco: 'mco',
        mst: 'mst'
    )
);

// submit
$checkoutResponse = PaymayaFacade::createCheckout($checkout);

echo 'id: '.$checkoutResponse->checkoutId."\n";
echo 'url: '.$checkoutResponse->redirectUrl."\n";

// retrieve
PaymayaFacade::getCheckout($checkoutResponse->checkoutId);

Webhook

https://developers.maya.ph/reference/createv1webhook-1

# see config `maya.webhooks` array to set your webhooks,
# then run this to create webhooks.

php artisan maya:webhook:create


# get all webhooks

php artisan maya:webhook:all


# 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 Saloon Client Mock

Sample usage of client mock https://docs.saloon.dev/the-basics/testing

    
    use Lloricode\Paymaya\Requests\Checkout\CreateCheckoutRequest;
    use Saloon\Http\Faking\MockClient;
    use Saloon\Http\Faking\MockResponse;

    /**
     * @test
     */
    public function success_checkout() 
    {
            $paymayaID = 'test-maya-generated-id';
            $paymayaRedirectUrl = 'http://test-maya/redirect-url';
    
            MockClient::global([
                CreateCheckoutRequest::class => new MockResponse(
                    body: [
                        'checkoutId' => $paymayaID,
                        'redirectUrl' => $paymayaRedirectUrl,
                    ]
                ),
            ]);
            
           // your 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.

统计信息

  • 总下载量: 190
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-01