# PHP SDK

# Github IEPay PHP SDK (opens new window)

https://github.com/MIEPayOpenSource/iepay-php-sdk

# Composer Install

composer require iepay/iepay-php-sdk

# Usage

# Create IEPayClient

use IEPaySDK\BaseClient;

use IEPaySDK\Observer\SignatureObserver;

class IEPayClient extends BaseClient {

    public function __construct(string $apiKey)
    {
        $this->addObserver(new SignatureObserver($apiKey));

        $origin = 'https://a.mypaynz.com';

        parent::__construct($origin);
    }
}

# Create General Order

use IEPaySDK\IEPayClient;
use IEPaySDK\Requests\GeneralOrderRequest;

$client = new IEPayClient('iepay_api_key');

$request = new GeneralOrderRequest();

$body = [
    'mid' => '10000',                        // mid
    'total_fee' => 1000,                     // 分为单位的金额
    'goods' => 'Iphone',                     // 任意字符串
    'goods_detail' => 'An Iphone 12',        // 任意字符串
    'out_trade_no' => '2020102204514282',    // out_trade_no
    'pay_type'    => 'IE0011',               // 参考 https://iepay-api.netlify.app/online/order/create/#parameter-info
    'return_url' => $return_url,
    'notify_url' => $notify_url,
    'expired' => 3600,
    'version' => 'v1'
];

$request->buildBody($body);

$response = $client->execute($request);

# Create Wechat Mini Program Order

use IEPaySDK\IEPayClient;
use IEPaySDK\Requests\WechatMiniAppOrderRequest;

$client = new IEPayClient('iepay_api_key');

$request = new WechatMiniAppOrderRequest();

$body = [
    'mid' => '10000',                        // mid
    'appid' => 'wxxxxxxxxxx',                // 小程序的appid
    'openid' => 'ZhdowQs12Ed',               // 用户在小程序中的openid
    'total_fee' => 1000,                     // 以分为单位的价格
    'goods' => 'Iphone',                     // 任意字符串
    'goods_detail' => 'An Iphone 12',        // 任意字符串
    'out_trade_no' => '2020102204514282',    // out_trade_no
    'pay_type' => 'IE0026',                  // IE0026 是小程序支付的标识,此接口只能传IE0026
    'return_url' => $return_url,
    'notify_url' => $notify_url,
    'expired' => 3600,
    'version' => 'v1'
];

$request->buildBody($body);

$response = $client->execute($request);

# Refund Order

use IEPaySDK\IEPayClient;
use IEPaySDK\Requests\RefundOrderRequest;

$client = new IEPayClient('iepay_api_key');

$request = new RefundOrderRequest();

$body = [
    'mid' => '10000',                        // mid
    'out_trade_no' => '2020102204514282',    // out_trade_no
    'pay_type' => 'IE0011',                  // 退款订单的pay_type
    'refund_amount' => 1000,                 // 退款金额,单位分
    'refund_charge_fee' => 'TRUE',           // 可选,如果想退回用户所有的费用,设置为'TRUE',默认不退回手续费
    'version' => 'v1'
];

$request->buildBody($body);

$response = $client->execute($request);