PHP code example of bocapro / boca-payments

1. Go to this page and download the library: Download bocapro/boca-payments library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bocapro / boca-payments example snippets


use BetterFutures\BocaPayments\Facades\BocaPayments;
use BetterFutures\BocaPayments\Data\Customer;
use BetterFutures\BocaPayments\Enums\Currency;
use BetterFutures\BocaPayments\Enums\Gateway;

$response = BocaPayments::setAmount(99.99)
    ->setCurrency(Currency::USD)
    ->setCustomer(new Customer(email: '[email protected]', firstName: 'John', lastName: 'Doe'))
    ->setDescription('Order #1234')
    ->setReturnUrl('https://myapp.com/payment/success')
    ->setCancelUrl('https://myapp.com/payment/cancel')
    ->pay();

$response = BocaPayments::gateway(Gateway::PayPal)
    ->setAmount(50.00)
    ->setCurrency(Currency::USD)
    ->setCustomer(new Customer(email: '[email protected]'))
    ->pay();

$response->status;          // PaymentStatus::Completed, Pending, Failed, RequiresAction, etc.
$response->paymentId;       // "pi_3abc123" - store this in your orders table
$response->redirectUrl;     // "https://..." - for gateways that redirect (PayPal, MercadoPago)
$response->html;            // rendered html for gateways that need it
$response->message;         // "succeeded"
$response->raw;             // full raw gateway response

$response->isSuccessful();     // true if completed
$response->

if ($response->irect($response->redirectUrl);
}

// payment completed
return view('payment.success', ['payment_id' => $response->paymentId]);

$response = BocaPayments::verify($paymentId);

if ($response->isSuccessful()) {
    // mark order as paid
}

// full refund
$refund = BocaPayments::refund(paymentId: $paymentId);

// partial refund
$refund = BocaPayments::refund(paymentId: $paymentId, amount: 25.00, reason: 'Customer request');

if ($refund->isSuccessful()) {
    // refund processed
}

use Smpita\TypeAs\TypeAs;

$response = BocaPayments::gateway(Gateway::from($request->input('gateway')))
    ->setAmount(TypeAs::float($request->input('amount')))
    ->setCurrency(Currency::USD)
    ->setCustomer(new Customer(email: TypeAs::string($request->input('email'))))
    ->pay();

// valid strings: stripe, paypal, plaid, mercadopago, authorize_net, justifi, global_payment

use BetterFutures\BocaPayments\Facades\BocaPayments;
use BetterFutures\BocaPayments\Data\Customer;
use BetterFutures\BocaPayments\Enums\Currency;
use BetterFutures\BocaPayments\Enums\Gateway;
use Smpita\TypeAs\TypeAs;

class PaymentController extends Controller
{
    public function pay(Request $request)
    {
        $response = BocaPayments::gateway(Gateway::from($request->input('gateway', 'stripe')))
            ->setAmount(TypeAs::float($request->input('amount')))
            ->setCurrency(Currency::USD)
            ->setCustomer(new Customer(
                email: TypeAs::string($request->input('email')),
                firstName: TypeAs::nullableString($request->input('first_name')),
                lastName: TypeAs::nullableString($request->input('last_name')),
            ))
            ->setReturnUrl(route('payment.verify'))
            ->pay();

        if ($response->
bash
php artisan vendor:publish --tag="boca-payments-config"