ronmelkhior/coinpayments-ipn

简单直观的Coinpayments IPN

v1.0.5 2017-03-08 13:36 UTC

This package is auto-updated.

Last update: 2024-09-15 04:52:30 UTC


README

Coinpayments-IPN 是一个简单的PHP包,让您轻松处理Coinpayments的IPN请求,无需任何麻烦。

免责声明

目前,此包仅支持Coinpayments中的HTTP Auth IPN方法。

用法

首先,通过Composer安装此包

composer require ronmelkhior/coinpayments-ipn

然后按照以下方式将IPN添加到您的代码中

<?php

use RonMelkhior\CoinpaymentsIPN\IPN;

$ipn = new IPN();

初始化 IPN 类后,您需要使用 setMerchantIDsetIPNSecret 方法设置商户ID和IPN密钥。

<?php

use RonMelkhior\CoinpaymentsIPN\IPN;

$ipn = new IPN();
$ipn->setMerchantID('your-id-here')
    ->setIPNSecret('your-secret-here');

然后,您可以使用 validate 方法验证IPN,您需要提供您的 $_POST$_SERVER 数组。

<?php

use RonMelkhior\CoinpaymentsIPN\IPN;

$ipn = new IPN();
$ipn->setMerchantID('your-id-here')
    ->setIPNSecret('your-secret-here');

try {
    if ($ipn->validate($_POST, $_SERVER)) {
        // Payment was successful, verify vars such as the transaction ID/email and process it.
    } else {
        // IPN worked, but the payment is pending.
    }
} catch (RonMelkhior\CoinpaymentsIPN\Exceptions\InvalidRequestException $e) {
    // The IPN data was not valid to begin with (missing data, invalid IPN method).
} catch (RonMelkhior\CoinpaymentsIPN\Exceptions\InsufficientDataException $e) {
    // Sufficient data provided, but either the merchant ID or the IPN secret didn't match.
} catch (RonMelkhior\CoinpaymentsIPN\Exceptions\FailedPaymentException $e) {
    // IPN worked, but the payment has failed (PayPal refund/cancelled/timed out).
}