Accept your first payment in 5 minutes
Step 1 - Install the SDK
- TypeScript
- Python
- Go
- cURL
npm install @accend/sdk
pip install accend
go get github.com/accend/sdk-go
export ACCEND_API_KEY=sk_test_your_key
Step 2 - Create a product
- TypeScript
- Python
- Go
- cURL
import { createAccend } from "@accend/sdk";
const accend = createAccend({
apiKey: process.env.ACCEND_API_KEY!,
baseUrl: "https://api.accend.now"
});
const product = await accend.products.create({
name: "Pro Plan",
type: "one_time",
defaultPrice: {
model: "one_time",
amount: "97.00",
currency: "BRL"
}
});
from accend import Accend
import os
accend = Accend(api_key=os.environ["ACCEND_API_KEY"], base_url="https://api.accend.now")
product = accend.products.create({
"name": "Pro Plan",
"type": "one_time",
"defaultPrice": {
"model": "one_time",
"amount": "97.00",
"currency": "BRL",
},
})
client := accend.New(os.Getenv("ACCEND_API_KEY"), "https://api.accend.now")
product, _ := client.CreateProduct(ctx, map[string]any{
"name": "Pro Plan",
"type": "one_time",
"defaultPrice": map[string]any{
"model": "one_time",
"amount": "97.00",
"currency": "BRL",
},
})
_ = product
curl -X POST "https://api.accend.now/v1/products" \
-H "Authorization: Bearer $ACCEND_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{
"name": "Pro Plan",
"type": "one_time",
"defaultPrice": {
"model": "one_time",
"amount": "97.00",
"currency": "BRL"
}
}'
Step 3 - Create a checkout
- TypeScript
- Python
- Go
- cURL
const customer = await accend.customers.create({
externalId: "user_123",
email: "owner@example.com"
});
const checkout = await accend.checkout.createSession({
mode: "payment",
customerId: customer.data.id,
productId: product.data.id,
amount: "97.00",
currency: "BRL",
successUrl: "https://yourapp.com/success",
cancelUrl: "https://yourapp.com/cancel"
});
customer = accend.customers.create({
"externalId": "user_123",
"email": "owner@example.com",
})
checkout = accend.checkout.create_session({
"mode": "payment",
"customerId": customer["data"]["id"],
"productId": product["data"]["id"],
"amount": "97.00",
"currency": "BRL",
"successUrl": "https://yourapp.com/success",
"cancelUrl": "https://yourapp.com/cancel",
})
customer, _ := client.CreateCustomer(ctx, map[string]any{
"externalId": "user_123",
"email": "owner@example.com",
})
customerData := customer["data"].(map[string]any)
productData := product["data"].(map[string]any)
checkout, _ := client.CreateCheckoutSession(ctx, map[string]any{
"mode": "payment",
"customerId": customerData["id"],
"productId": productData["id"],
"amount": "97.00",
"currency": "BRL",
"successUrl": "https://yourapp.com/success",
"cancelUrl": "https://yourapp.com/cancel",
})
_ = checkout
curl -X POST "https://api.accend.now/v1/checkout/sessions" \
-H "Authorization: Bearer $ACCEND_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{
"mode": "payment",
"customerId": "cus_123",
"productId": "prod_123",
"amount": "97.00",
"currency": "BRL",
"successUrl": "https://yourapp.com/success",
"cancelUrl": "https://yourapp.com/cancel"
}'
Step 4 - Share the link
- TypeScript
- Python
- Go
- cURL
redirect(checkout.data.checkoutUrl);
checkout_url = checkout["data"]["checkoutUrl"]
checkoutData := checkout["data"].(map[string]any)
checkoutURL := checkoutData["checkoutUrl"].(string)
_ = checkoutURL
# Read checkoutUrl from the response body and send your customer there.
Step 5 - Receive the webhook
- TypeScript
- Python
- Go
- cURL
app.post("/webhooks/accend", async (req, res) => {
const event = req.body;
if (event.type === "checkout.paid") {
const { customerId, productId } = event.data;
await grantAccess(customerId, productId);
}
res.sendStatus(200);
});
@app.post("/webhooks/accend")
def handle_accend_webhook():
event = request.json
if event["type"] == "checkout.paid":
grant_access(event["data"]["customerId"], event["data"]["productId"])
return ("", 200)
http.HandleFunc("/webhooks/accend", func(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
var event map[string]any
_ = json.NewDecoder(r.Body).Decode(&event)
if event["type"] == "checkout.paid" {
data := event["data"].(map[string]any)
grantAccess(data["customerId"].(string), data["productId"].(string))
}
w.WriteHeader(http.StatusOK)
})
# Webhooks are delivered by Accend to the endpoint you configure in the dashboard.