benoth/boa-compra

Unofficial BoaCompra billing PHP library

1.0.3 2015-09-25 11:47 UTC

This package is not auto-updated.

Last update: 2024-04-27 15:58:17 UTC


README

Software License Build Status Coverage Status Quality Score SensioLabsInsight

This package is compliant with PSR-1, PSR-2 and PSR-4. If you notice compliance oversights, please send a patch via pull request.

Requirements

The following versions of PHP are supported:

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

The following extensions are also required:

  • curl
  • mbstring

Usage

Create a payment

$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();

Validate BoaCompra notification

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();
}

Check the status of a payment

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

The API documentation is available on Github Pages

Testing

$ vendor/bin/phpunit

License

The MIT License (MIT). Please see License File for more information.