An API client library for Stripe payment gateway.
We can install this library using the following statements:
import "Apm";
Apm.importPackage("Alusus/Stripe@0.4");
import "Apm";
Apm.importPackage("Alusus/Stripe@0.4");
use Stripe;
// Inistantiate the client.
def client: Stripe.Client(String("my_test_key"));
// Variable to hold all the balance of stripe account.
def balanceArray : Array[SrdRef[Balance]];
// Get the balance.
balanceArray = client.getBalance();
// Print the balance array.
def j: Int;
for j = 0, j < balanceArray.getLength(), j++ {
Console.print(
"type: %s\ncurrency: %s\namount: %f\ndetailed source:\n",
balanceArray(j).balanceType.buf, balanceArray(j).currency.buf, balanceArray(j).amount
);
def i: Int;
for i = 0, i < balanceArray(j).sources.getLength(), i++ {
Console.print(
"\tsource type: %s\n\tsource amount: %f\n",
balanceArray(j).sources(i).sourceType.buf, balanceArray(j).sources(i).amount
)
}
Console.print("\n");
}
This class holds the properties of a customer from Stripe API.
class Customer {
def id: String;
def address: SrdRef[Address];
def balance: Float = 0;
def defaultSourceId: String;
def delinquent: Bool;
def created: Int[64];
def email: String;
def invoicePrefix: String;
def preferredLocales: Array[String];
def name: String;
def phone: String;
def shipping: String;
def taxExempt: String;
def testClock: String;
def nextInvoiceSequence: Int;
def currency: String;
def description: String;
def defaultPaymentMethod: String;
handler this~init();
handler this~init(id: String, email: String, name: String, preferredLocales: Array[String]);
handler this~init(
id: String, address: SrdRef[Address], balance: Float, created: Int[64],
currency: String, defaultSourceId: String, delinquent: Bool,
description: String, email: String, invoicePrefix: String, name: String,
nextInvoiceSequence: Int, phone: String, preferredLocales: Array[String],
shipping: String, taxExempt: String, testClock: String, defaultPaymentMethod: String
);
}
Holds physical address information.
class Address {
def city: String;
def country: String;
def line1: String;
def line2: String;
def postalCode: String;
def state: String;
handler this~init();
handler this~init(city: String, country: String, line1: String, line2: String, postalCode: String, state: String);
}
This class holds the details of a balance object from Stripe API.
class Balance {
def amount: Float = 0;
def currency: String = "usd";
def sources: Array[SrdRef[Source]];
def balanceType: String;
handler this~init() {
}
handler this~init(amount: Float, currency: String, sources: Array[SrdRef[Source]], balanceType: String);
}
def sources: Array[SrdRef[Source]]
The sources of the balance (bank_account, card).
def balanceType: String
The type of the balance (available, pending).
This class holds the properties of a balance transaction object from Stripe API.
class BalanceTransaction {
def id: String;
def amount: Float = 0;
def availableOn: Int[64];
def created: Int[64];
def currency: String = "usd";
def description: String;
def exchangeRate: Float;
def fee: Float;
def feeDetails: Array[String];
def net: Float = 0;
def reportingCategory: String;
def source: String;
def status: String;
def sourceType: String;
handler this~init();
handler this~init(
id: String, amount: Float, availableOn: Int[64], created: Int[64],
currency: String, description: String, exchangeRate: Float, fee: Float,
feeDetails: Array[String], net: Float, reportingCategory: String,
source: String, status: String, sourceType: String
);
}
def id: String
The id of the BalanceTransaction object from Stripe.
def amount: Float
The amount of the transaction.
def availableOn: Int[64]
The time this amount will be available.
def exchangeRate: Float
The exchange rate of the transaction.
def fee: Float
The fee on this transaction.
Carries billing details for a customer.
class BillingDetails {
def address: SrdRef[Address];
def email: String;
def name: String;
def phone: String;
handler this~init();
handler this~init(
address: SrdRef[Address], email: String, name: String, phone: String
);
}
This class holds the properties of a checkout object from Stripe API.
class CheckoutSession {
def id: String;
def cancelUrl: String;
def uniqeId: String;
def currency: String = "usd";
def customerId: String;
def lineItems: String;
def mode: String;
def paymentStatus: String;
def status: String;
def successUrl: String;
def url: String;
def amountTotal: String;
handler this~init();
handler this~init(
id: String, uniqeId: String, cancelUrl: String, successUrl: String, url: String,
currency: String, customerId: String, lineItems: String,
mode: String, paymentStatus: String, status: String, amountTotal: String
);
}
def id: String
The ID of the checkout object from Stripe.
def cancelUrl: String
The url to redirect to if the checkout is canceled.
def successUrl: String
The url to redirect to if the checkout is successful.
def url: String
The checkout url.
def amountTotal: String
The total amount of the transaction.
Carries information of a single payment method.
class PaymentMethod {
def id: String;
def billingDetails: SrdRef[BillingDetails];
def created: Int[64];
def currency: String = "usd";
def customerId: String;
def expYear: Int;
def expMonth: Int;
def last4: String;
def type: String;
handler this~init();
handler this~init(
id: String, billingDetails: SrdRef[BillingDetails], created: Int[64], expYear: Int, expMonth: Int,
currency: String, last4: String, type: String
);
}
Holds the info of a single source contributing to a balance.
class Source {
def amount: Float = 0;
def sourceType: String = "card"; // "card" or "bank_account"
handler this~init();
handler this~init(amount: Float, sourceType: String);
}
This class holds the properties of a Subscription object from Stripe API.
class Subscription {
def id: String;
def application: String;
def automaticTax: Bool;
def billingCycleAnchor: Int[64];
def created: Int[64];
def startDate: Int[64];
def currentPeriodStart: Int[64];
def currentPeriodEnd: Int[64];
def cancelAtPeriodEnd: Bool;
def description: String;
def status: String;
def trialEnd: Int[64];
def currency: String = "usd";
def customerId: String;
def collectionMethod: String;
def metadata: Map[String, String];
handler this~init();
handler this~init(
id: String, automaticTax: Bool, billingCycleAnchor: Int[64], created: Int[64],
collectionMethod: String, startDate: Int[64], cancelAtPeriodEnd: Bool,
currentPeriodEnd: Int[64], currentPeriodStart: Int[64], description: String, status: String,
trialEnd: Int[64], customerId: String, currency: String, metadata: Map[String, String]
);
}
def id: String
The id of the Subscription object from Stripe.
def created: Int[64]
The timestamp of the creation date.
def startDate: Int[64]
The timestamp of the subscription start date.
def cancelAtPeriodEnd: Bool
End the subscription when the current invice end.
def status: String
The status of the subscription.
def trialEnd: Int[64]
The timestamp of the subscription trail period end.
class Coupon {
def id: String;
def name: Nullable[String];
def duration: String;
def durationInMonths: Nullable[String];
def amountOff: Nullable[Int];
def percentOff: Nullable[Float];
def currency: Nullable[String];
handler this~init();
handler this~init(
id: String,
name: Nullable[String],
duration: String,
durationInMonths: Nullable[String],
amountOff: Nullable[Int],
percentOff: Nullable[Float],
currency: Nullable[String]
);
}
class PromotionCode {
def id: String;
def active: Bool;
def code: String;
def livemode: Bool;
def coupon: SrdRef[Coupon];
handler this~init() {}
handler this~init(
id: String,
active: Bool,
code: String,
livemode: Bool,
coupon: SrdRef[Coupon]
);
}
This class has methods for all available calls to Stripe.
handler this~init(k: String)
Initialize the client with a Stripe API key.
handler this.getCustomers(): Possible[Array[SrdRef[Customer]]]
handler this.getCustomers(limit: Int): Possible[Array[SrdRef[Customer]]]
handler this.getCustomers(limit: Int, startId: String): Possible[Array[SrdRef[Customer]]]
Returns all customers.
limit: The max number of records to return.startId: The ID of the record after which to start retrieving records. The record with this ID will not be included in the result.
handler this.getCustomer(id: String): Possible[SrdRef[Customer]]
Returns a specific customer by its ID.
handler this.createCustomer(parameters: String): Possible[String]
Creates a customer entry. Returns the customer's id.
parameters: The parameters of the customer object in the form"email=user123@example.com&name=john".
handler this.doesCustomerHaveDefaultPaymentMethod(customerId: String): Bool
Returns 1 if the customer with the given ID has a default payment method.
handler this.addCustomerDefaultPaymentMethod(customerId: String, paymentMethodId: String): SrdRef[Error]
Assigns the payment method with the given ID as the customer's default payment method. Returns 1 on success.
handler this.getBalance(): Possible[Array[SrdRef[Balance]]]
Returns the balance of all the accounts owned by the API key.
handler this.getBalanceTranasactions(): Possible[Array[SrdRef[BalanceTranasaction]]]
handler this.getBalanceTranasactions(limit: Int): Possible[Array[SrdRef[BalanceTranasaction]]]
handler this.getBalanceTranasactions(limit: Int, startId: String): Possible[Array[SrdRef[BalanceTranasaction]]]
Returns a list of transactions that have contributed to the Stripe account balance (e.g., charges, transfers, and so forth).
limit: The max number of records to return.startId: The ID of the record after which to start retrieving records. The record with this ID will not be included in the result.
handler this.getBalanceTranasaction(id: String): Possible[SrdRef[BalanceTranasaction]]
Retrieves the balance transaction with the given ID.
handler this.getCheckoutSessions(): Possible[Array[SrdRef[CheckoutSession]]]
handler this.getCheckoutSessions(limit: Int): Possible[Array[SrdRef[CheckoutSession]]]
handler this.getCheckoutSessions(limit: Int, startId: String): Possible[Array[SrdRef[CheckoutSession]]]
Returns a list of Checkout Sessions.
limit: The max number of records to return.startId: The ID of the record after which to start retrieving records. The record with this ID will not be included in the result.
handler this.getCheckoutSession(sessionId: String): Possible[SrdRef[CheckoutSession]]
Gets a specific checkout session by its ID.
handler this.createCheckoutSession(parameters: String): Possible[String]
handler this.createCheckoutSession(items: Map[String, Int], successUrl: CharsPtr): Possible[String]
handler this.createCheckoutSession(items: Map[String, Int], customerId: String, successUrl: CharsPtr): Possible[String]
Creates a checkout session. Returns CheckoutSession id. The first version takes a raw parameters string; the other two receive detailed parameters instead.
parameters: The parameters of the checkout session in the form"customer=customerID&line_items=planID".items: A map whose key is the price ID from Stripe, and whose value is the quantity wanted for that price ID.customerId: The id of the customer.successUrl: The URL to redirect the user to after successful payment.
handler this.getSubscriptions(): Possible[Array[SrdRef[Subscription]]]
handler this.getSubscriptions(filterQuery: String): Possible[Array[SrdRef[Subscription]]]
Returns the list of subscriptions.
filterQuery: The query to use to filter the records. Only records matching this criteria will be returned.
handler this.getSubscription(subscriptionId: String): Possible[SrdRef[Subscription]]
Gets a specific subscription by its ID.
handler this.createSubscription(parameters: String): Possible[String]
handler this.createSubscription(items: Map[String, Int], customerId: String): Possible[String]
Creates a subscription. Returns Subscription id. The first version takes a raw parameters string; the second receives detailed parameters instead.
parameters: The parameters of the subscription in the form"customer=customerID&line_items=planID".items: A map whose key is the price ID from Stripe, and whose value is the quantity wanted for that price ID.customerId: The id of the customer.
handler this.updateSubscription(subscriptionId: String, parameters: String): Possible[String]
Updates the subscription having the given ID.
parameters: The parameters to assign to this subscription in the format"customer=customerID&line_items=planID".
handler this.cancelSubscription(subscriptionId: String): SrdRef[Error]
Cancels the subscription having the given ID.
handler this.createBillingPortalSession(parameters: String): Possible[String]
handler this.createBillingPortalSession(customerId: CharsPtr, returnUrl: CharsPtr): Possible[String]
Creates a billing portal session. Returns customer account url. The first version takes a raw parameters string; the second receives detailed parameters instead.
parameters: The parameters of the billing portal session in the form"customer=customerID&return_url=returnUrl".customerId: The id of the customer.returnUrl: The URL to redirect the user to after closing the portal session.
handler this.getPaymentMethods(customerId: String): Possible[Array[SrdRef[PaymentMethod]]]
Returns the payment methods of the customer with the given ID.
handler this.getPaymentMethod(paymentMethodId: String): Possible[SrdRef[PaymentMethod]]
Returns the payment method having the given ID.
handler this.getPromotionCodes(code: String): Possible[Array[SrdRef[PromotionCode]]]
Gets the promotion codes matching the provided code.
The Errors submodule contains error codes for all errors that can be returned by this library.
Errors.UNAUTHENTICATED: Returned when calling Stripe with an invalid key.Errors.CONNECTION: Returned when connection fails.Errors.UNEXPECTED: Returned when receiving unexpected response from Stripe.Errors.NOT_FOUND: Returned when the requested record is not found.Errors.INVALID_PARAM: Returned when the operation fails due to an invalid param.
class InvalidParamError {
def paramName: String;
}
Copyright (C) 2026 Sarmad Abdullah
This project is licensed under the GNU Lesser General Public License v3.0 (LGPL-3.0). See the COPYING and COPYING.LESSER files for details.