salamander/easy-coda-pay

make coda pay easy to integrate

1.1.0 2019-12-10 07:25 UTC

This package is not auto-updated.

Last update: 2020-09-30 07:14:53 UTC


README

PHP Coda package

Installation

Install using composer:

composer require salamander/easy-coda-pay

Configuration

<?php
$config = [
    'airtimeURL' => 'https://sandbox.codapayments.com/airtime/', // 这里是测试地址,正式环境换成`https://airtime.codapayments.com/airtime/`
    'airtimeRestURL' => 'https://sandbox.codapayments.com/airtime/api/restful/v1.0/Payment', // 这里是测试地址,正式环境换成`https://airtime.codapayments.com/airtime/api/restful/v1.0/Payment`
    'apikey' => '<YOUR SITE API KEY>',
    'country'    => '360', // 国家,如360,文档:https://online.codapayments.com/merchant/developer/references#currency_codes
    'currency'   => '360', // 货币,如360
    'payType'    => '1', // 支付方式 => for example DCB = 1
    'requestType' => 'json',
];
$payUtil = new Salamander\PhpCoda\PaymentUtil($config);

Usage

Make Order

<?php
$orderRequest = [
    'orderId' => (string) round(microtime(true) * 1000),  // 商户订单号
    'goods' => [
        [
            'name' => 'C',   // goods name
            'code' => '23', // Merchant-managed item code. 
            'price' => 12.5, // Float
        ],
        [
            'name' => 'C',
            'code' => '23',
            'price' => 12.5,
        ],
    ]
];
$config = []; // above configuration
$payUtil = new Salamander\PhpCoda\PaymentUtil($config);
$resp = $payUtil->makeOrder($orderRequest);
echo $resp->txnId;
$mobileJumpUrl = $payUtil->getMobileJumpUrl($resp->txnId); // 移动端页面跳转URL

goods item informatio

Name Type Length Description
code String 128 Merchant-managed item code.
name String 128 The name of the purchased item or topup, e.g. “50 diamonds”. If purchases can be made for multiple games or services, include also the name of that, e.g. “Hero's Glory - 200 gold”.
price Float N/A The price of the item (inclusive of any taxes) in the currency specified in the request message.
type Numeric N/A default=1

Transaction Completion Notification

When a payment transaction has been completed, Codapay notifies your application using the “Transaction Completion Notification URL”. Note that by default, Coda ONLY sends notifications for Successful transactions (not for Pending or Failed transactions). This is a web application URL using the HTTP/1.1 Get method with the following HTTP parameters.

Name Type Length Description
TxnId Numeric N/A Unique TxnId returned from Init() Method call.
OrderId String 64 Unique transaction identifier passed by Init() Method request message from Merchant.
ResultCode Numeric N/A Success or error code. Success = 0. Error codes can be found here.
TotalPrice Float N/A
PaymentType Numeric 3 PaymentType selected by customer
Checksum String 512 Refer to security section

Validate Checksum

<?php
$config = []; // above configuration
$payUtil = new Salamander\PhpCoda\PaymentUtil($config);
$getParams = [
    'TxnId' => '*****',
    'OrderId' => '*****',
    'ResultCode' => '******',
    'Checksum' => '******',
];
$checkRes = $payUtil->validateChecksum($getParams); // 校验签名