定制 aceraven777/laravel-paymaya 二次开发

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

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

aceraven777/laravel-paymaya

Composer 安装命令:

composer require aceraven777/laravel-paymaya

包简介

PayMaya Payment integration to Laravel

README 文档

README

Build Status

Integrated PayMaya SDK (https://github.com/PayMaya/PayMaya-PHP-SDK) and port it to Laravel.

Installation

Run the following command to install:

composer require aceraven777/laravel-paymaya "~1.1"

Run the following command to publish User library file:

php artisan vendor:publish --provider "Aceraven777\PayMaya\PayMayaServiceProvider"

Usage

When you run php artisan vendor:publish it will create file in config/paymaya.php and app/Libraries/PayMaya/User.php, you may edit this file based on your needs.

For the sample codes below you have to define PAYMAYA_PUBLIC_KEY and PAYMAYA_SECRET_KEY in your .env file for your API keys. Here's the link for sandbox API keys for PayMaya: https://developers.maya.ph/reference/sandbox-credentials-and-cards#sandbox-api-keys

Setting up Webhooks

use Aceraven777\PayMaya\PayMayaSDK;
use Aceraven777\PayMaya\API\Webhook;

public function setupWebhooks()
{
    PayMayaSDK::getInstance()->initCheckout(
        config('paymaya.public_key'),
        config('paymaya.secret_key'),
        (app()->environment('production') ? 'PRODUCTION' : 'SANDBOX')
    );

    $this->clearWebhooks();

    $successWebhook = new Webhook();
    $successWebhook->name = Webhook::CHECKOUT_SUCCESS;
    $successWebhook->callbackUrl = url('callback/success');
    $successWebhook->register();

    $failureWebhook = new Webhook();
    $failureWebhook->name = Webhook::CHECKOUT_FAILURE;
    $failureWebhook->callbackUrl = url('callback/error');
    $failureWebhook->register();

    $dropoutWebhook = new Webhook();
    $dropoutWebhook->name = Webhook::CHECKOUT_DROPOUT;
    $dropoutWebhook->callbackUrl = url('callback/dropout');
    $dropoutWebhook->register();
}

private function clearWebhooks()
{
    $webhooks = Webhook::retrieve();
    foreach ($webhooks as $webhook) {
        $webhook->delete();
    }
}

Customize Merchant Page

use Aceraven777\PayMaya\PayMayaSDK;
use Aceraven777\PayMaya\API\Customization;

public function customizeMerchantPage()
{
    PayMayaSDK::getInstance()->initCheckout(
        config('paymaya.public_key'),
        config('paymaya.secret_key'),
        (app()->environment('production') ? 'PRODUCTION' : 'SANDBOX')
    );

    $shopCustomization = new Customization();
    $shopCustomization->get();

    $shopCustomization->logoUrl = asset('logo.jpg');
    $shopCustomization->iconUrl = asset('favicon.ico');
    $shopCustomization->appleTouchIconUrl = asset('favicon.ico');
    $shopCustomization->customTitle = 'PayMaya Payment Gateway';
    $shopCustomization->colorScheme = '#f3dc2a';

    $shopCustomization->set();
}

Checkout

use Aceraven777\PayMaya\PayMayaSDK;
use Aceraven777\PayMaya\API\Checkout;
use Aceraven777\PayMaya\Model\Checkout\Item;
use App\Libraries\PayMaya\User as PayMayaUser;
use Aceraven777\PayMaya\Model\Checkout\ItemAmount;
use Aceraven777\PayMaya\Model\Checkout\ItemAmountDetails;

public function checkout()
{
    PayMayaSDK::getInstance()->initCheckout(
        config('paymaya.public_key'),
        config('paymaya.secret_key'),
        (app()->environment('production') ? 'PRODUCTION' : 'SANDBOX')
    );

    $sample_item_name = 'Product 1';
    $sample_total_price = 1000.00;

    $sample_user_phone = '1234567';
    $sample_user_email = 'test@gmail.com';
    
    $sample_reference_number = '1234567890';

    // Item
    $itemAmountDetails = new ItemAmountDetails();
    $itemAmountDetails->tax = "0.00";
    $itemAmountDetails->subtotal = number_format($sample_total_price, 2, '.', '');
    $itemAmount = new ItemAmount();
    $itemAmount->currency = "PHP";
    $itemAmount->value = $itemAmountDetails->subtotal;
    $itemAmount->details = $itemAmountDetails;
    $item = new Item();
    $item->name = $sample_item_name;
    $item->amount = $itemAmount;
    $item->totalAmount = $itemAmount;

    // Checkout
    $itemCheckout = new Checkout();

    $user = new PayMayaUser();
    $user->contact->phone = $sample_user_phone;
    $user->contact->email = $sample_user_email;

    $itemCheckout->buyer = $user->buyerInfo();
    $itemCheckout->items = array($item);
    $itemCheckout->totalAmount = $itemAmount;
    $itemCheckout->requestReferenceNumber = $sample_reference_number;
    $itemCheckout->redirectUrl = array(
        "success" => url('returl-url/success'),
        "failure" => url('returl-url/failure'),
        "cancel" => url('returl-url/cancel'),
    );
    
    if ($itemCheckout->execute() === false) {
        $error = $itemCheckout::getError();
        return redirect()->back()->withErrors(['message' => $error['message']]);
    }

    if ($itemCheckout->retrieve() === false) {
        $error = $itemCheckout::getError();
        return redirect()->back()->withErrors(['message' => $error['message']]);
    }

    return redirect()->to($itemCheckout->url);
}

Webhook Callback

use Illuminate\Http\Request;
use Aceraven777\PayMaya\PayMayaSDK;
use Aceraven777\PayMaya\API\Checkout;

public function callback(Request $request)
{
    PayMayaSDK::getInstance()->initCheckout(
        config('paymaya.public_key'),
        config('paymaya.secret_key'),
        (app()->environment('production') ? 'PRODUCTION' : 'SANDBOX')
    );

    $transaction_id = $request->get('id');
    if (! $transaction_id) {
        return ['status' => false, 'message' => 'Transaction Id Missing'];
    }
    
    $itemCheckout = new Checkout();
    $itemCheckout->id = $transaction_id;

    $checkout = $itemCheckout->retrieve();

    if ($checkout === false) {
        $error = $itemCheckout::getError();
        return redirect()->back()->withErrors(['message' => $error['message']]);
    }

    return $checkout;
}

Void Payment

use Aceraven777\PayMaya\PayMayaSDK;
use Aceraven777\PayMaya\API\VoidPayment;

public function voidPayment($checkoutId)
{
    PayMayaSDK::getInstance()->initCheckout(
        config('paymaya.public_key'),
        config('paymaya.secret_key'),
        (app()->environment('production') ? 'PRODUCTION' : 'SANDBOX')
    );

    $voidPayment = new VoidPayment;
    $voidPayment->checkoutId = $checkoutId;
    $voidPayment->reason = 'The item is out of stock.';

    $response = $voidPayment->execute();

    if ($response === false) {
        $error = $voidPayment::getError();
        return redirect()->back()->withErrors(['message' => $error['message']]);
    }

    return $response;
}

Refund Payment

Refund a checkout.

use Aceraven777\PayMaya\PayMayaSDK;
use Aceraven777\PayMaya\API\RefundPayment;
use Aceraven777\PayMaya\Model\Refund\Amount;

public function refundPayment($checkoutId)
{
    PayMayaSDK::getInstance()->initCheckout(
        config('paymaya.public_key'),
        config('paymaya.secret_key'),
        (app()->environment('production') ? 'PRODUCTION' : 'SANDBOX')
    );

    $refundAmount = new Amount();
    $refundAmount->currency = "PHP";
    $refundAmount->value = 200.22;

    $refundPayment = new RefundPayment;
    $refundPayment->checkoutId = $checkoutId;
    $refundPayment->reason = 'The item is out of stock.';
    $refundPayment->amount = $refundAmount;

    $response = $refundPayment->execute();

    if ($response === false) {
        $error = $refundPayment::getError();
        return redirect()->back()->withErrors(['message' => $error['message']]);
    }

    return $response;
}

Get refund attempts of a checkout.

use Aceraven777\PayMaya\PayMayaSDK;
use Aceraven777\PayMaya\API\RefundPayment;

public function retrieveRefunds($checkoutId)
{
    PayMayaSDK::getInstance()->initCheckout(
        config('paymaya.public_key'),
        config('paymaya.secret_key'),
        (app()->environment('production') ? 'PRODUCTION' : 'SANDBOX')
    );

    $refundPayment = new RefundPayment;
    $refundPayment->checkoutId = $checkoutId;
    
    $refunds = $refundPayment->retrieve();

    if ($refunds === false) {
        $error = $refundPayment::getError();
        return redirect()->back()->withErrors(['message' => $error['message']]);
    }

    return $refunds;
}

Retrieve information of a particular refund.

use Aceraven777\PayMaya\PayMayaSDK;
use Aceraven777\PayMaya\API\RefundPayment;

public function retrieveRefundInfo($checkoutId, $refundId)
{
    PayMayaSDK::getInstance()->initCheckout(
        config('paymaya.public_key'),
        config('paymaya.secret_key'),
        (app()->environment('production') ? 'PRODUCTION' : 'SANDBOX')
    );

    $refundPayment = new RefundPayment;
    $refundPayment->checkoutId = $checkoutId;
    $refundPayment->refundId = $refundId;

    $refund = $refundPayment->retrieveInfo();

    if ($refund === false) {
        $error = $refundPayment::getError();
        return redirect()->back()->withErrors(['message' => $error['message']]);
    }

    return $refund;
}

Donate

Via GCash

Logo

Via PayPal

Donate

aceraven777/laravel-paymaya 适用场景与选型建议

aceraven777/laravel-paymaya 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24.14k 次下载、GitHub Stars 达 18, 最近一次更新时间为 2018 年 05 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 aceraven777/laravel-paymaya 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 aceraven777/laravel-paymaya 我们能提供哪些服务?
定制开发 / 二次开发

基于 aceraven777/laravel-paymaya 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 24.14k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 18
  • 点击次数: 20
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 18
  • Watchers: 4
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-05-13