nigel/contipay-php

Contipay PHP 客户端

2.0.3 2024-06-13 11:31 UTC

This package is auto-updated.

Last update: 2024-09-13 13:28:49 UTC


README

要求

  1. ContiPay 账户

  2. ContiPay 密钥和密钥

工作原理

1. 使用 Composer 安装最新版本

composer require nigel/contipay-php

2. 需要自动加载文件和类导入

<?php
use Contipay\Core\Contipay;
use Contipay\Helpers\Payload\PayloadGenerator;

require_once __DIR__ . '/vendor/autoload.php';


$webhookUrl = "https://www.contipay.co.zw/api/webhook";
$successUrl = "https://www.contipay.co.zw/api/success";
$cancelUrl = "https://www.contipay.co.zw/api/cancel";
$merchantCode = 00;
$phone = "2637****340";
$amount = (float) 10;

$contipay = new Contipay(
    'token-here', // copy from .env or paste directly
    'secret-here', // copy from .env or paste directly
);

3. 处理支付

i. 基本直接支付示例

$payload = (new PayloadGenerator($merchantCode, $webhookUrl))
    ->setUpProviders('InnBucks', 'IB')
    ->simpleDirectPayload(
        $amount,
        $phone,
    );

$res = $contipay->setAppMode("DEV")
    ->setPaymentMethod()
    ->process($payload);

header('Content-type: application/json');

echo $res;

ii. 基本重定向支付示例

$payload = (
    new PayloadGenerator(
        $merchantCode,
        $webhookUrl,
        $successUrl,
        $cancelUrl
    )
)->simpleRedirectPayload(
        $amount,
        $phone
    );

$res = $contipay->setAppMode("DEV")
    ->setPaymentMethod('redirect')
    ->process($payload);

header('Content-type: application/json');

echo $res;

iii. 直接支付示例

$payload = (
    new PayloadGenerator(
        $merchantCode,
        $webhookUrl
    )
)->setUpCustomer('Nigel', 'Jaure', $phone, 'ZW', 'nigeljaure@gmail.com')
    ->setUpProviders('Ecocash', 'EC')
    ->setUpAccountDetails($phone, 'Nigel Jaure')
    ->setUpTransaction($amount, "USD")
    ->directPayload();

$res = $contipay
    ->setAppMode("DEV")
    ->setPaymentMethod()
    ->process($payload);

header('Content-type: application/json');

echo $res;

iv. 重定向支付示例

$payload = (
    new PayloadGenerator(
        $merchantCode,
        $webhookUrl,
        $successUrl,
        $cancelUrl
    )
)->setUpCustomer('Nigel', 'Jaure', $phone, 'ZW', 'nigeljaure@gmail.com')
    ->setUpTransaction($amount, "USD")
    ->redirectPayload();

$res = $contipay->setAppMode("DEV")
    ->setPaymentMethod('redirect')
    ->process($payload);

header('Content-type: application/json');

echo $res;;

4. 支付分配

$privateKey = <<<EOD
-----BEGIN PRIVATE KEY-----
     YOUR KEY HERE 
-----END PRIVATE KEY-----
EOD;

$payload = (
    new PayloadGenerator(
        $merchantCode,
        $webhookUrl
    )
)->setUpCustomer('Nigel', 'Jaure', $phone, 'ZW', 'nigeljaure@gmail.com')
    ->setUpProviders('Transfer', 'TF')
    ->setUpAccountDetails($phone, 'Nigel Jaure')
    ->setUpTransaction($amount, "USD")
    ->directPayload();

$res = $contipay
    ->setAppMode("DEV")
    ->setPaymentMethod()
    ->disburse($payload, $privateKey);

header('Content-type: application/json');

echo $res;

附加说明

  • 方法 updateURL 是可选的,仅在 URL 发生变化时适用。使用它来相应地更新 URL。以下是使用方法:
$contipay = new Contipay(
    'token-here', // copy from .env or paste directly
    'secret-here', // copy from .env or paste directly
);

// Update URLs if necessary
$contipay->updateURL('dev-url', 'live-url');

// Process payment with the updated URLs
$res = $contipay
    ->setAppMode("DEV")  // LIVE as another option
    ->setPaymentMethod()
    ->process($payload);

header('Content-type: application/json');

echo $res;
  • 在处理支付之前,请确保使用 setAppMode 方法设置适当的模式(DEVLIVE)。

  • 提供的示例涵盖了基本场景,包括直接和重定向支付方法、客户信息设置和交易详情。

  • ContiPay JavaScript 替代方案 这里