Skip to content

****# SDK

Introduction ​

Our libraries connects your code to our payment API.

Python, Typescript (NodeJS) and PHP are supported.

Installation ​

Requirements ​

SDK VersionMinimum PHPTested up to
1.x7.18.2
2.x8.18.4

Use composer:

bash
composer install stancer/stancer

Setup ​

Set your API keys once per request:

php
use Stancer;

$config = new Stancer\Config();
$config->setKeys(["ptest_xxxx", "pprod_xxx", "stest_xxx", "sprod_xxx"]);

WARNING

Never write API keys in your code. Use a vault or environment variables, to keep them secure.

API Version ​

Default Version in PHP and python SDK is version 1 (legacy). To change version:

php
$config->setVersion(2);

Core concepts ​

Create an object ​

php
$object = new Stancer\Object();

Create an object with data ​

php
$object = new Stancer\Object(["data1" => 0, "data2" => "foo"]);

Get an existing object ​

php
$object = new Stancer\Object("obj_xxx");

Data loads only when you access it (e.g., $object->getData()).

List objects ​

All object can be listed

php
$listOfObjects = object::list([
    'created' => 1761661063,
    'created_until' => 1900000000,
    'limit' => 100,
    'start' => 0,
]);
ParameterType:Required
createdDateTime, timestamp, or DatePeriodYes
created_untilDateTime or timestampNo
limitintNo
startintNo

Send an object ​

php
$object->send();

This handles GET, POST, and PATCH automatically based on object state.

Get creation date ​

php
$object->getCreated();
// or
$object->getCreatedAt();

Objects overview ​

ObjectPurpose
Payment IntentsCreate and manage transactions
PaymentCreate and manage payments
CardCredit/debit card payment method
SEPABank debit payment method
CustomerCustomer information
RefundProcess refunds
PayoutView payouts (read-only)
DisputeView disputes (read-only)

Payment Intents ​

Payment intents is the core object. Use it to create transactions and process payments.

Create a payment intent ​

php
$paymentIntent = new Stancer\PaymentIntent();

Authentication ​

php
$paymentIntent->setAuth(true);

INFO

Sending without authentication is deprecated. Use boolean (true).

Send a payment ​

Payment Intents needs at least an amount (in cents, and over 50 cents) and a currency in order to send it.

php
$paymentIntent->setAmount(100); // in cents
$paymentIntent->setcurrency(Stancer\Currency::EUR);
$paymentIntent->send();

Capture a payment intent ​

Manual capture (default): At the end of the payment process the payment intent is authorized you still need to capture it to change the status to processing.

php
$paymentIntent->capture();

Instant capture: If you set capture to true, the payment intent will automaticaly be capture at the end of the payment process.

php
$paymentIntent->setCapture(true);

Process a payment intent ​

Retrieve a payment page url:

php
$paymentIntent->setReturnUrl("https://stancer.com");
$url = $paymentIntent->getPaymentPageUrl();

The url can be embedded or you can redirect to it.

Payments ​

Use payment intent in favor of payment.

Some status can be more detailed on payment.

Retrieve a payment ​

  1. Via a payment Intents a. get The last payment linked to a payment intent
php
$payment = $paymentIntent->getPayment();

b. get the list of payment linked to a payment intent

php
$paymentList = $paymentIntent->getPayments();
  1. Directly by ID
php
$payment = new Stancer\Payment('paym_xxx');

Refund a payment ​

php
$payment->refund(50); // cents, keep empty for full refund

WARNING

Full refund: requires authorized payment.

Partial refund: requires captured payment (usually 24 hour after the authorization).

Cards ​

WARNING

Card data is sensitive. You must follow PCI DSS rules based on your transaction volume.

FieldRequirement
Number16-19 digits (never store this)
Exp Month1-12
Exp YearCurrent year to 2099
CVC3 digits (never store this)
php
$card = new Stancer\Card();
$card->setNumber("4242424242424242"); // test card number
$card->setExpMonth(12);
$card->setExpYear(2050);
$card->setCvc("021"); // CVC is a string, not an int

INFO

Store only last4, never the full card number.

SEPA ​

Bank debit requires activation on your account.

FieldRequirement
NameAccount holder name
IBANValid IBAN
MandateFor payment capture
Mandate DateFor payment capture
php
$sepa = new Stancer\Sepa();
$sepa->setName("Gilles Dupont");
$sepa->setIban("FR9430003000409249176322Z50");
$sepa->setMandate("mndt_xxx");
$sepa->setDateMandate($date_mandate); // DateTime object

Customers ​

At least email or mobile required.

FieldRequirement
Name3-64 characters
Email3-64 characters
MobileValid phone number
BillingAddressAddress
php
$customer = new Stancer\Customer();
$customer->setName('John Doe');
$customer->setEmail("example@example.com");

Refunds ​

Create via Payment object or via Refund object:

php
$refund = new Stancer\Refund();
$refund->setPayment($payment);
$refund->setAmount(50); // cents, omit for full refund
$refund->send();

Payouts and Disputes ​

Created by the Stancer API.

You can only read or list them.

php
$payout = new Stancer\Payout("pout_xxx");
$dispute = new Stancer\Dispute("dspt_xxx");