****# SDK
Introduction
Our libraries connects your code to our payment API.
Python, Typescript (NodeJS) and PHP are supported.
Installation
Requirements
| SDK Version | Minimum PHP | Tested up to |
|---|---|---|
| 1.x | 7.1 | 8.2 |
| 2.x | 8.1 | 8.4 |
Use composer:
composer install stancer/stancerSetup
Set your API keys once per request:
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:
$config->setVersion(2);Core concepts
Create an object
$object = new Stancer\Object();Create an object with data
$object = new Stancer\Object(["data1" => 0, "data2" => "foo"]);Get an existing object
$object = new Stancer\Object("obj_xxx");Data loads only when you access it (e.g., $object->getData()).
List objects
All object can be listed
$listOfObjects = object::list([
'created' => 1761661063,
'created_until' => 1900000000,
'limit' => 100,
'start' => 0,
]);| Parameter | Type: | Required |
|---|---|---|
| created | DateTime, timestamp, or DatePeriod | Yes |
| created_until | DateTime or timestamp | No |
| limit | int | No |
| start | int | No |
Send an object
$object->send();This handles GET, POST, and PATCH automatically based on object state.
Get creation date
$object->getCreated();
// or
$object->getCreatedAt();Objects overview
| Object | Purpose |
|---|---|
| Payment Intents | Create and manage transactions |
| Payment | Create and manage payments |
| Card | Credit/debit card payment method |
| SEPA | Bank debit payment method |
| Customer | Customer information |
| Refund | Process refunds |
| Payout | View payouts (read-only) |
| Dispute | View disputes (read-only) |
Payment Intents
Payment intents is the core object. Use it to create transactions and process payments.
Create a payment intent
$paymentIntent = new Stancer\PaymentIntent();Authentication
$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.
$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.
$paymentIntent->capture();Instant capture: If you set capture to true, the payment intent will automaticaly be capture at the end of the payment process.
$paymentIntent->setCapture(true);Process a payment intent
Retrieve a payment page url:
$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
- Via a payment Intents a. get The last payment linked to a payment intent
$payment = $paymentIntent->getPayment();b. get the list of payment linked to a payment intent
$paymentList = $paymentIntent->getPayments();- Directly by ID
$payment = new Stancer\Payment('paym_xxx');Refund a payment
$payment->refund(50); // cents, keep empty for full refundWARNING
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.
| Field | Requirement |
|---|---|
| Number | 16-19 digits (never store this) |
| Exp Month | 1-12 |
| Exp Year | Current year to 2099 |
| CVC | 3 digits (never store this) |
$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 intINFO
Store only last4, never the full card number.
SEPA
Bank debit requires activation on your account.
| Field | Requirement |
|---|---|
| Name | Account holder name |
| IBAN | Valid IBAN |
| Mandate | For payment capture |
| Mandate Date | For payment capture |
$sepa = new Stancer\Sepa();
$sepa->setName("Gilles Dupont");
$sepa->setIban("FR9430003000409249176322Z50");
$sepa->setMandate("mndt_xxx");
$sepa->setDateMandate($date_mandate); // DateTime objectCustomers
At least email or mobile required.
| Field | Requirement |
|---|---|
| Name | 3-64 characters |
| 3-64 characters | |
| Mobile | Valid phone number |
| BillingAddress | Address |
$customer = new Stancer\Customer();
$customer->setName('John Doe');
$customer->setEmail("example@example.com");Refunds
Create via Payment object or via Refund object:
$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.
$payout = new Stancer\Payout("pout_xxx");
$dispute = new Stancer\Dispute("dspt_xxx");