benoth/boa-compra

非官方BoaCompra计费PHP库

1.0.3 2015-09-25 11:47 UTC

This package is not auto-updated.

Last update: 2024-09-28 18:21:22 UTC


README

Software License Build Status Coverage Status Quality Score SensioLabsInsight

此包符合 PSR-1PSR-2PSR-4 标准。如果您发现不符合标准的地方,请通过pull request发送补丁。

需求

以下PHP版本受支持

  • PHP 5.4
  • PHP 5.5
  • PHP 5.6
  • PHP 7
  • HHVM

还需要以下扩展

  • curl
  • mbstring

使用方法

创建支付

$vsi = new VirtualStoreIdentification($yourStoreId, $yourSecretKey);

try {
    $endUser = new EndUser('me@example.com');
    $endUser->setName('John Doe')
            // ...
            ->setLanguage('en_US');

    $payment = new Payment(
        $vsi,
        $endUser,
        $yourReturnUrl,
        $yourNotifyUrl,
        $yourCurrencyIso,
        $yourOrderId,
        $orderDescription,
        $amount // without dot or comma (ie: 500 for $5.00)
    );
    $payment->setTestMode(1)
            ->setProjectId(1)
            ->setPaymentId(1);
} catch (\Exception $e) {
	// Log or anything ...
}

$form = new PaymentFormGenerator($payment);

// Then in your HTML code, just call :
$form->render();

验证BoaCompra通知

try {
    // $payment is your previously set Payment object
	$notif = new PaymentNotification(
	    $payment,
	    $_POST['store_id'],
	    $_POST['transaction_id'],
	    $_POST['order_id'],
	    $_POST['amount'],
	    $_POST['currency_code'],
	    $_POST['payment_id'],
	    $_SERVER['REMOTE_ADDR']
	);
	$postback = new PaymentPostBack($notif);
	$postback->validatePayment();
	return 'Ok !';
} catch (\Exception $e) {
	return 'Error validating the payment : '.$e->getMessage();
}

检查支付状态

try {
	$notif = new PaymentNotification(
	    $payment,
	    $storeId,
	    $transactionId,
	    $orderId,
	    $amount,
	    $currencyCode,
	    $paymentId
	);
	$status = new PaymentCheckStatus($notif);
	$status->validatePayment();
	return 'Ok !';
} catch (\Exception $e) {
	return 'Error validating the payment : '.$e->getMessage();
}

API

API文档可在Github Pages上找到

测试

$ vendor/bin/phpunit

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件