remzikocak/laravel-vallet 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

remzikocak/laravel-vallet

最新稳定版本:2.1.0

Composer 安装命令:

composer require remzikocak/laravel-vallet

包简介

Unofficial Vallet Payment Gateway Integration for Laravel.

README 文档

README

Laravel Options

Vallet Integration for Laravel 10/11/12

This Package helps you to integrate Vallet Payment Gateway in your Laravel Application.

This is an unofficial, third party package.

Installation

You can install the package via composer:

composer require remzikocak/laravel-vallet

Configuration

Publish the config file with:

php artisan vendor:publish --provider="RKocak\Vallet\ValletServiceProvider" --tag="config"

Add the following variables to your .env file and fill them with your credentials:

VALLET_USERNAME=
VALLET_PASSWORD=
VALLET_SHOPCODE=
VALLET_HASH=
VALLET_CALLBACK_OK_URL=
VALLET_CALLBACK_FAIL_URL=

VALLET_CALLBACK_OK_URL and VALLET_CALLBACK_FAIL_URL are the urls that Vallet will redirect the user after payment is completed or failed. Make sure that you have created a route for these URLs in your routes file.

Usage

How to Create a Payment

use RKocak\Vallet\Facades\Vallet;
use RKocak\Vallet\Buyer;
use RKocak\Vallet\Enums\{Currency, Locale, ProductType};
use RKocak\Vallet\Exceptions\{RequestFailedException, InvalidArgumentException, BuyerNotSetException, LocaleNotSetException, CurrencyNotSetException};

class YourController {

    public function yourMethod()
    {
        // Create a new buyer object
        $buyer = new Buyer();
        $buyer->setName('Remzi')
              ->setSurname('Kocak')
              ->setEmail('hey@remzikocak.com')
              ->setCity('Istanbul')
              ->setCountry('Turkey')
              ->setDistrict('Atasehir')
              ->setPhoneNumber('5555555555')
              ->setAddress('Atasehir, Istanbul')
              ->setIp('127.0.0.1');
        
        // Create a new payment object
        $payment = Vallet::createPayment();
        
        // Set Payment Details
        $payment->setBuyer($buyer)
                ->setLocale(Locale::Turkish)
                ->setCurrency(Currency::Try)
                ->setConversationId('123456789')
                ->setOrderId('123456789')
                ->setProductName('Test Product')
                ->setTotalPrice(100)
                ->setOrderPrice(100)
                ->setProductType(ProductType::Digital);
                
        // Add Products
        $payment->addProduct(
            Product::make()
                ->setName('Test Product')
                ->setPrice(13.50)
                ->setType(ProductType::Digital)
        );
        
        try {
            // Send Payment Request
            $paymentLink = $payment->getLink();
            
            // You can redirect user to '$paymentLink' or you can use it as a href in your button
            // Depending on your needs
        } catch (RequestFailedException|InvalidArgumentException|BuyerNotSetException|LocaleNotSetException|CurrencyNotSetException $e) {
            // Handle Exception
        }    
    }

}

Retrieve Payment Details

use RKocak\Vallet\Facades\Vallet;
use RKocak\Vallet\Exceptions\{InvalidHashException, InvalidResponseException};

class YourController
{

    public function yourMethod(){
        try {
            // Retrieve Payment Details
            $response = Vallet::getResponse();
            $response->validate();
            
            
            if($response->isPaid()) {
                // Payment is paid
                $amount = $response->getAmount();
                $orderId = $response->getOrderId();
                $valletOrderId = $response->getValletOrderId();
                
                // Update your order status, send email etc.
            } else {
                // Payment is not paid, is pending or is awaiting verification
            }
        } catch (InvalidHashException|InvalidResponseException $e) {
            // Handle Exception
        }
    }

}

Important: You should store the $response->getValletOrderId() in your database. You will need it for refunding the payment.

Refund Payment

use RKocak\Vallet\Facades\Vallet;

class YourController {

    public function yourMethod()
    {
        $refund = Vallet::createRefund();

        try {
            // Set Refund Details
            $refund->setOrderId('123456789')
                   ->setValletOrderId('123456789')
                   ->setAmount(100);
            
            // Send Refund Request
            $response = $refund->process();
            
            if($response->success()) {
                $refundId = $response->getRefundId();
            } else {
                // Refund is not successful
            }
        } catch (InvalidArgumentException $e) {
            // Handle Exception
        }
    }

}

Important: You should store the $response->getRefundId() in your database. You will need it to get Support from Vallet Customer Service.

Publishing Translation Files

Vallet Integration for Laravel comes with English, Turkish and German translations. If you want to customize them, you can publish them with:

php artisan vendor:publish --provider="RKocak\Vallet\ValletServiceProvider" --tag="lang"

Testing

composer test

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-10-27