Search by

althosalud / cobros

gonzaloalonsod

Typed PHP SDK for the AlthoCobros checkout API

v1.1.0 2026-10-27 02:37 UTC

This package is auto-updated.

Last update: 2026-10-27 02:38:24 UTC


README

Cliente PHP tipado para la AlthoCobros Checkout API.

Sin dependencias de framework: PHP 8.2+, ext-curl, ext-hash.

Instalación

composer require althosalud/cobros

Uso

use AlthoSalud\Cobros\CobrosClient;
use AlthoSalud\Cobros\Dto\CheckoutLineRequest;
use AlthoSalud\Cobros\Dto\CreateCheckoutRequest;
use AlthoSalud\Cobros\EntitlementSignature;

$client = new CobrosClient(
    baseUrl: CobrosClient::DEFAULT_BASE_URL, // https://cobros.althoapp.com (DEFAULT_PRODUCTION_BASE_URL is a deprecated alias)
    apiKey: 'cb_...',
);

$me = $client->me();
// $me->commissionBps, $me->commissionMode

$checkout = $client->createCheckout(new CreateCheckoutRequest(
    lines: [new CheckoutLineRequest(
        amountCents: 15000,
        currency: 'ARS',
        description: 'Plan mensual',
        sku: 'althosalud.pro',
        periodStart: '2026-08-01',
        periodEnd: '2026-08-31',
        entitlementRef: 'org-42:2026-08',
        customerExternalId: 'org-42',
    )],
    customerExternalId: 'org-42',
    idempotencyKey: 'org-42-2026-08',
    backUrls: [
        'success' => 'https://tu-app.example/pago/ok',
        'failure' => 'https://tu-app.example/pago/error',
    ],
));

// Arrays also work for backward compatibility:
// $client->createCheckout([...], idempotencyKey: '...');

// Redirect the payer:
$checkout->initPoint;
// Commission breakdown:
// $checkout->subtotalAmountCents, $checkout->commissionAmountCents,
// $checkout->totalAmountCents, $checkout->netAmountCents

$paid = $client->getCheckout($checkout->id);

baseUrl acepta con o sin barra final (https://cobros.althoapp.com y https://cobros.althoapp.com/ son equivalentes).

Webhook entitlement.paid

$event = EntitlementSignature::parse(
    rawBody: $request->getContent(),
    signatureHeader: (string) $request->headers->get('X-Cobros-Signature'),
    secret: $applicationWebhookSecret,
    idempotencyKey: $request->headers->get('X-Cobros-Idempotency-Key'),
);
// $event->sku, amountCents, periodStart, customerExternalId
// $event->checkoutCommissionBps, checkoutTotalAmountCents, ...

withApiKey() is immutable (one key per tenant).