alkhatibdev/laravel-zain 问题修复 & 功能扩展

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

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

alkhatibdev/laravel-zain

最新稳定版本:v1.0.0

Composer 安装命令:

composer require alkhatibdev/laravel-zain

包简介

Zain DSP API integration

README 文档

README

Social Card of Laravel Zain Package

Zain DSP API integration with Laravel

Latest Version MIT Licensed

Introduction

Laravel Zain is Zain DSP API integration with Laravel, made to simplify the process and API calls and let developers focus on other integration parts and logic. See also Laravel Sudani.

Installation

Requirements

  • PHP >= 7.4.x
  • Laravel >= 7.x

install via composer

composer require alkhatibdev/laravel-zain

Publish Configs

php artisan vendor:publish --tag=laravel-zain-config

A laravel-zain.php config file will be published on your configs directory, with the following content:

<?php

return [

    'base_url' => env('ZAIN_SERVER_BASE_API_URL'),

    'product_code' => env('ZAIN_PRODUCT_CODE'),

    'username' => env('ZAIN_USERNAME'),

    'password' => env('ZAIN_PASSWORD'),

    'remember_token' => env('ZAIN_REMEMBER_TOKEN', false),

    'enable_logging' => false,
];

Don't forget to set all these variable on your .env file

ZAIN_SERVER_BASE_API_URL=https://test.zaindsp.com:3030/api/v1/json/
ZAIN_PRODUCT_CODE=xxxxxx
ZAIN_USERNAME=xxxxx
ZAIN_PASSWORD=xxxxx
ZAIN_REMEMBER_TOKEN=false

Usage

Initial Payment/Subscription

use AlkhatibDev\LaravelZain\Facades\Zain;

// Initiate payment request
$response = Zain::initiate($phone)

When initiate payment request successfully sent, a SMS with OTP code will be send to the $phone number, and $response will contain a subscribe_request_id and you should save it to the next step verify.

Verify Payment/Subscription

$response = Zain::verify($otp, $requestId)

Check Subscription

$response = Zain::checkSubscription($phone)

Unsubscribe

$response = Zain::unsubscribe($phone)

// cacheToken($response['token'])

Login and Cache DSP token

Out of the box the package will login automatically and get the token and use it for each action initiate, verify ..etc per request.

If you want to cache the token and use it for furthor requests, you can request token like this:

$token = Zain::token()

And you can cache it and use it for each request for the next 24 hours. If you set ZAIN_REMEMBER_TOKEN=true token will be expired after 30 days.

Example of using cached token:

// $token = getCachedToken()

$response = Zain::withToken($token)->initiate($phone)
$response = Zain::withToken($token)->verify($phone)
...

Logging

You can enable logging from package config file

'enable_logging' => true,

Other Packages

License

Laravel Zain is open-sourced software licensed under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-07-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固