Overview
Thetangle.client.billing package provides functionality for requesting payment links and managing subscription lifecycles.
Requesting Payment Links
To subscribe to a plan or upgrade, request a payment link that redirects users to a payment processor.RequestPaymentLink
Generate a payment link for subscribing to a plan.URL to redirect the user to after completing or canceling payment
Identifier of the subscription plan to purchase
Billing cycle for the subscription. Valid values: “monthly” or “yearly”
Protocol Definition
The
billing_period field should be set to either “monthly” for monthly billing or “yearly” for annual billing.Response: PaymentLink
The server responds with aPaymentLink containing the URL to the payment processor.
The payment processor URL where the user should be redirected to complete payment
Protocol Definition
Canceling Subscriptions
Cancel an active subscription.CancelSubscription
This message cancels the user’s current subscription.This message has no parameters. The server cancels the subscription for the authenticated user.
Usage Flow
Subscribing to a Plan
- Request Payment Link: Send
RequestPaymentLinkwith the desired plan, billing period, and redirect URL - Receive Payment URL: Server responds with
PaymentLinkcontaining the payment processor URL - Redirect User: Navigate the user to the payment URL
- Complete Payment: User completes payment on the payment processor’s site
- Handle Redirect: User is redirected back to the specified
redirect_url - Verify Subscription: Check subscription status to confirm activation
Canceling a Subscription
- Request Cancellation: Send
CancelSubscriptionmessage - Confirmation: Server processes the cancellation request
- Access Period: User retains access until the end of the current billing cycle
- Subscription Ends: Premium features are disabled when the subscription expires
Example Workflow
Best Practices
- Always use HTTPS for redirect URLs to ensure secure payment processing
- Validate the
billing_periodfield to only accept “monthly” or “yearly” - Handle payment failures gracefully by checking subscription status after redirect
- Provide clear confirmation UI when users cancel subscriptions
- Display subscription status and expiration dates prominently
- Allow users to resubscribe easily if they’ve previously canceled
Security Considerations
- Payment processing is handled by external payment processors
- Never store credit card information in client applications
- Validate redirect URLs to prevent open redirect vulnerabilities
- Use secure, authenticated sessions when requesting payment links
- Implement proper error handling for failed payment attempts