Client libraries and examples
Payware has client libraries for TypeScript, Python, Go, Rust, PHP and Ruby. They are generated from the same OpenAPI document as the reference, so every operation in the API is a method, with typed requests and responses. A library is a thin wrapper over the HTTP API described in these guides: the endpoints, fields, errors and conventions are the same.
What is the same in every language
| Authentication | Give the library your API key (sk_test_… / sk_live_…) as its access token; it sends Authorization: Bearer …. |
| Server | https://api.payware.dev. |
| Method names | The verb plus the resource: listCustomers, createCustomer, retrieveCustomer, updateCustomer, deleteCustomer, and actions such as resolvePayment or cancelPaymentLink. Each language writes them its own way (create_payment_link in Python, Ruby and Rust; CreatePaymentLink in Go). |
| Idempotency | Every operation that accepts an Idempotency-Key header has a parameter for it (idempotencyKey, idempotency_key, IdempotencyKey). Send one on every create. |
| Pagination | List methods take the same limit and starting_after parameters as the API. |
| Errors | A non-2xx answer is raised as an error that carries the status code and the error envelope: ResponseError (TypeScript), ApiException (Python and PHP), a non-nil error with the *http.Response (Go), Error::ResponseError (Rust), Payware::ApiError (Ruby). |
Download
Each library is a zip with the full source of the package (version 0.1.0). Unzip it next to your project and install it from the folder:
| Language | Download | Install from the unzipped folder |
|---|---|---|
| TypeScript | payware-typescript-0.1.0.zip | npm install ./payware-typescript-0.1.0 (builds on install; import from @payware/sdk) |
| Python | payware-python-0.1.0.zip | pip install https://payware.dev/sdk/payware-python-0.1.0.zip, or pip install ./payware-python-0.1.0 |
| Go | payware-go-0.1.0.zip | go mod edit -replace github.com/payware/payware-go=./payware-go-0.1.0 and go get github.com/payware/payware-go |
| Rust | payware-rust-0.1.0.zip | in Cargo.toml: payware = { path = "./payware-rust-0.1.0" } |
| PHP | payware-php-0.1.0.zip | a Composer path repository to ./payware-php-0.1.0, then composer require payware/payware-php |
| Ruby | payware-ruby-0.1.0.zip | in the Gemfile: gem "payware", path: "./payware-ruby-0.1.0" |
Create a payment link
The same call in curl, then in each language. The amount is in minor units (1000 is 10.00 RON) and the key order-1042
makes a retry return the same link instead of creating a second one. Each program prints the link's url; set
PAYWARE_API_KEY to your key first. PAYWARE_BASE_URL is optional and only needed to talk to another server.
curl
curl -sS https://api.payware.dev/v1/payment-links \
-H "authorization: Bearer $PAYWARE_API_KEY" -H 'content-type: application/json' \
-H 'idempotency-key: order-1042' \
-d '{"kind":"payment","amount":1000,"currency":"RON","description":"Order 1042"}'
TypeScript
import { Configuration, PaymentLinksApi } from "@payware/sdk";
const config = new Configuration({
basePath: process.env.PAYWARE_BASE_URL, // optional: defaults to the production API
accessToken: process.env.PAYWARE_API_KEY,
});
const link = await new PaymentLinksApi(config).createPaymentLink({
idempotencyKey: "order-1042",
createPaymentLinkRequest: { kind: "payment", amount: 1000, currency: "RON", description: "Order 1042" },
});
console.log(link.url);
Python
import os
import payware
config = payware.Configuration(
host=os.environ.get("PAYWARE_BASE_URL"), # optional: defaults to the production API
access_token=os.environ["PAYWARE_API_KEY"],
)
with payware.ApiClient(config) as client:
request = payware.CreatePaymentLinkRequest(
payware.CreatePaymentLinkPaymentRequest(kind="payment", amount=1000, currency="RON", description="Order 1042")
)
link = payware.PaymentLinksApi(client).create_payment_link(request, idempotency_key="order-1042")
print(link.url)
Go
package main
import (
"context"
"fmt"
"os"
payware "github.com/payware/payware-go"
)
func main() {
cfg := payware.NewConfiguration()
if base := os.Getenv("PAYWARE_BASE_URL"); base != "" { // optional: defaults to the production API
cfg.Servers = payware.ServerConfigurations{{URL: base}}
}
client := payware.NewAPIClient(cfg)
ctx := context.WithValue(context.Background(), payware.ContextAccessToken, os.Getenv("PAYWARE_API_KEY"))
payment := payware.NewCreatePaymentLinkPaymentRequest("payment", 1000, "RON")
payment.SetDescription("Order 1042")
body := payware.CreatePaymentLinkPaymentRequestAsCreatePaymentLinkRequest(payment)
link, _, err := client.PaymentLinksAPI.CreatePaymentLink(ctx).
IdempotencyKey("order-1042").
CreatePaymentLinkRequest(body).
Execute()
if err != nil {
panic(err)
}
fmt.Println(link.GetUrl())
}
Rust
use payware::apis::{configuration::Configuration, payment_links_api};
use payware::models;
#[tokio::main]
async fn main() {
let mut config = Configuration::new();
if let Ok(base) = std::env::var("PAYWARE_BASE_URL") {
config.base_path = base; // optional: defaults to the production API
}
config.bearer_access_token = std::env::var("PAYWARE_API_KEY").ok();
let mut payment = models::CreatePaymentLinkPaymentRequest::new(
models::create_payment_link_payment_request::Kind::Payment,
1000,
models::create_payment_link_payment_request::Currency::Ron,
);
payment.description = Some("Order 1042".into());
let body = models::CreatePaymentLinkRequest::CreatePaymentLinkPaymentRequest(payment);
let link = payment_links_api::create_payment_link(&config, body, Some("order-1042"))
.await
.expect("create payment link");
println!("{}", link.url.unwrap_or_default());
}
PHP
<?php
require 'vendor/autoload.php';
$config = Payware\Configuration::getDefaultConfiguration()->setAccessToken(getenv('PAYWARE_API_KEY'));
if ($base = getenv('PAYWARE_BASE_URL')) {
$config->setHost($base); // optional: defaults to the production API
}
$payment = new Payware\Model\CreatePaymentLinkPaymentRequest([
'kind' => 'payment', 'amount' => 1000, 'currency' => 'RON', 'description' => 'Order 1042',
]);
$api = new Payware\Api\PaymentLinksApi(new GuzzleHttp\Client(), $config);
$link = $api->createPaymentLink($payment, 'order-1042');
echo $link->getUrl(), "\n";
Ruby
require "uri"
require "payware"
Payware.configure do |c|
c.access_token = ENV.fetch("PAYWARE_API_KEY")
if (base = ENV["PAYWARE_BASE_URL"]) # optional: defaults to the production API
uri = URI(base)
c.scheme = uri.scheme
c.host = "#{uri.host}:#{uri.port}"
c.server_index = nil
end
end
payment = Payware::CreatePaymentLinkPaymentRequest.new(kind: "payment", amount: 1000, currency: "RON", description: "Order 1042")
link = Payware::PaymentLinksApi.new.create_payment_link(payment, idempotency_key: "order-1042")
puts link.url
The request body of a payment link is one of two shapes, told apart by kind: payment (one charge) and subscription
(see Payment links). In the libraries they are two types, CreatePaymentLinkPaymentRequest and
CreatePaymentLinkSubscriptionRequest, and the create method accepts either.
Read a list and an object
The remaining calls follow the same pattern: build the library's configuration once, call the method for the operation, and
read the typed result. For instance listCustomers (limit 2) and retrieveInvoice (by id) are, in Python:
customers = payware.CustomersApi(client).list_customers(limit=2)
invoice = payware.InvoicesApi(client).retrieve_invoice("01JC0000000000000000000000")
The reference lists every operation with its parameters and answers, and the library's method for it is the operation's name in the language's usual style.