Payments Configuration
Accept Payments from Users
Each payment gateway has its own method for handling payments and refunds. The Temp-Number Backend provides a unified interface for managing payments and refunds for multiple payment gateways. It includes support for popular gateways and can be extended to support additional ones.
Supported Payment Gateways
The Temp-Number Backend currently supports the following payment gateways:
How It Works
When a user makes a payment, the backend verifies the transaction and creates a record in the tn_payments database table. This record contains payment information including:
- Unique payment ID
- Firebase user ID
- Payment gateway identifier
- Payment amount
- Synchronization status (
is_syncedflag)
The backend attempts to synchronize the payment with the Platfone Retail API immediately. If synchronization fails, the is_synced flag remains false, and a background job periodically retries synchronization for unprocessed payments.
A positive amount increases the balance, while a negative amount decreases it (for refunds).
Payment Gateways Webhook Endpoints
Each payment gateway requires a webhook endpoint URL to notify the Temp-Number Backend of payment events. These URLs must be configured in the respective payment gateway dashboards to ensure proper payment processing.
Table of webhook endpoints:
| Payment Gateway | Webhook Endpoint URL Path |
|---|---|
| Stripe | /stripe-handleWebhookEvents |
| Apple App Store | /appstore-handleWebhookEvents |
| Google Play Store | /googleplay-handleWebhookEvents |
| PayPal | /paypal-handleWebhookEvents |
| Cryptomus | /cryptomus-handleWebhookEvents |
| Payeer | /payeer-handleWebhookEvents |
| Anypay | /anypay-handleWebhookEvents |
Given Backend URL https://your-domain.com/api/, the full Stripe webhook URL would be:
https://your-domain.com/api/stripe-handleWebhookEventsStripe
The Temp-Number Backend supports payments via the Stripe payment gateway.
Basic Process Overview:
- The app requests a payment intent from the Temp-Number Backend.
- The app sends the payment intent to Stripe.
- Stripe processes the payment and sends a webhook event to the Temp-Number Backend.
- The payment is verified and added to the database with either a positive amount (for payments) or a negative amount (for refunds).
Configuration:
- Set
STRIPE_ENABLED=trueduring the Temp-Number Backend installation. - Set up the Stripe webhook:
Go to the Stripe Dashboard and add a new endpoint.
Set the endpoint URL to
https://<your-backend-url>/stripe-handleWebhookEventsSelect the
payment_intent.amount_capturable_updated,charge.refundedandreview.closedevents, then click “Add endpoint” to save.Click “Reveal” to get the signing secret, which you’ll set as the
STRIPE_WEBHOOK_SECRETduring the Temp-Number Backend installation.
- Get your Stripe API keys:
- Go to Stripe Dashboard
to get your
Publishable keyandSecret key. You will be prompted for them during the backend installation.
- Go to Stripe Dashboard
to get your
- For instructions on configuring Stripe payments in your app, refer to the example apps:
Tip
- You can test Stripe payments using Stripe Test Cards .
- To test webhooks locally, consider using the Stripe CLI .
PayPal
The Temp-Number Backend supports payments via the PayPal Advanced Checkout integration .
Basic Process Overview:
Client-Side Integration:
- The app integrates PayPal’s JavaScript SDK to render PayPal buttons and card fields.
- Users interact with these components to initiate payments.
Server-Side Order Creation:
- The app sends a request to a Temp-Number Backend to create an order.
- The Backend utilizes PayPal’s Orders API to create the order and returns an
orderIDto the client.
Payment Approval:
- The client uses the
orderIDto approve the payment through PayPal’s SDK components.
- The client uses the
Order Capture:
- Upon approval, the client notifies the Temp-Number Backend to capture the order.
- The Backend captures the payment via PayPal’s Orders API and updates the Firestore database with the transaction details, recording positive amount.
Webhook Notification:
- PayPal sends a webhook
PAYMENT.CAPTURE.REFUNDEDevent to a designated Backend endpoint upon payment refund. - The Backend verifies the event and updates the Firestore database with the transaction details, recording negative amount.
- PayPal sends a webhook
Configuration:
Enable PayPal Integration:
- Set
PAYPAL_ENABLED=trueduring the Temp-Number Backend installation.
- Set
Obtain PayPal API Credentials:
- Log in to the PayPal Developer Dashboard .
- Navigate to Apps & Credentials and create a new REST API app.
- Retrieve your
Client IDandSecret, which will be required during the backend installation.
Set Up Webhook:
In the PayPal Developer Dashboard, go to Webhooks under your application settings.
Set the endpoint URL to
https://<your-backend-url>/paypal-handleWebhookEventsSubscribe to the following events:
- “Payment capture refunded”
PAYMENT.CAPTURE.REFUNDED(for refunds)
- “Payment capture refunded”
Save the webhook configuration.
Cryptomus
The Temp-Number Backend supports payments via the Cryptomus cryptocurrency payment gateway.
Basic Process Overview:
Client-Side Integration:
- The app integrates Cryptomus’s payment interface to facilitate cryptocurrency transactions.
- Users initiate payments through the app, selecting their preferred cryptocurrency.
Server-Side Invoice Creation:
- The app sends a request to a Temp-Number Backend to create a payment invoice.
- The Backend utilizes Cryptomus’s API to generate the invoice and returns the payment details to the client.
Payment Processing:
- Users complete the payment using the provided cryptocurrency details.
- Cryptomus processes the payment and confirms the transaction.
Webhook Notification:
- Cryptomus sends a webhook event to a designated Temp-Number Backend endpoint upon payment completion.
- The Backend verifies the payment and updates the database with the transaction details, recording positive amounts for payments and negative amounts for refunds.
Configuration:
Enable Cryptomus Integration:
- Set
CRYPTOMUS_ENABLED=trueduring the Temp-Number Backend installation.
- Set
Obtain Cryptomus API Credentials:
- Sign up on the Cryptomus website .
- Create a new merchant project to manage your payments.
- Generate your API keys from the merchant dashboard; these will be required during the backend installation.
Set Up Webhook:
In your Cryptomus merchant dashboard, navigate to the webhook settings.
Set the endpoint URL to
https://<your-backend-url>/cryptomus-handleWebhookEventsConfigure the webhook to listen for relevant events, such as payment completions and refunds.
Save the webhook configuration.
Client-Side Integration:
- Integrate Cryptomus’s payment interface into your app to facilitate cryptocurrency transactions.
- Ensure the client-side logic handles the initiation of payments and interacts with the Temp-Number Backend as needed.
For a visual walkthrough, you might find the following video helpful: https://www.youtube.com/watch?v=x71wO2kDRiI
Apple App Store
The Temp-Number Backend supports in-app purchases through the Apple App Store.
Basic Process Overview:
- The payment transaction provided by the app is verified and added to the database with a positive amount.
- When a
REFUNDApple App Store notification is received, it is verified and added to the database with a negative amount.
Configuration:
Set
APPSTORE_ENABLED=trueduring the Temp-Number Backend installation.Set up the notification URL in App Store Connect:
Go to App Store Connect .
In the
App Informationsection set the notification URL:https://<your-backend-url>/appstore-handleWebhookEvents
For instructions on configuring in-app purchases in your app, refer to the Apple in-app purchases section of the iOS example app documentation.
Google Play Store
The Temp-Number Backend supports in-app purchases through the Google Play Store.
Basic Process Overview:
- The payment transaction provided by the app is verified and added to the Firestore database with a positive amount.
- When a
ONE_TIME_PRODUCT_REFUNDEDGoogle Play Store notification is received, it is verified and added to the Firestore database with a negative amount.
Configuration:
Set
GOOGLE_PLAY_ENABLED=trueduring the Temp-Number Backend installation.Go to the Google Play Console and select your app.
Configure products under
Products -> In-app products.Create a service account key:
- Go to the Google Cloud Console .
- Select the project linked to your Play Store app, then click
Create Service Account. - Enter a name and description for the service account (e.g., temp-number-google-play), then click
Create. - Click
Create Keyand selectJSONas the key type. - Save the JSON file as
google-play-service-account.json.
Grant the service account access to app financial data:
- In the Google Play Console
, go to
Users and permissionsand clickInvite new users. - Paste the email address from the service account JSON file and select
Financeas the role. - In the app permission tab, click
Add appand select your app. - Allow the service account to access the financial data of the app.
- Click
Invite user.
- In the Google Play Console
, go to
Configure a Google Pub/Sub topic:
Go to the Google Cloud Console .
Click on
Create a topicand enter aTopic ID(a name for the topic).Click
Create.Choose
Subscriptionfor the created topic and clickEDIT.Change
Delivery typetoPushand paste the webhook URL into theEndpoint URL:https://<your-backend-url>/googleplay-handleWebhookEventsChange the
Retry policytoRetry after exponential backoff delay.Click
Update.
Grant the Google Play Store access to the Google Pub/Sub topic:
- In the Google Cloud Console , select the topic you created.
- Click on
ADD PRINCIPAL. - In the new principal field, enter
[email protected]. - Select the
RoleasPub/Sub Publisher.
Configure Google Play Store notifications:
- In the Google Play Console , select your app.
- Under the
Monetization setupsection inMonetize, checkEnable real-time notifications. - Fill in the
Topic namewith the name of the topic you created in the Google Cloud Console. - Set
Notification contentto includeSubscriptions, voided purchases, and all one-time products. - Click
Save changes.
Set
GOOGLE_PLAY_SECRET_FILEvariable during the Temp-Number Backend installation to include service account file contents. This should be a JSON string representing the contents of thegoogle-play-service-account.jsonfile created earlier.
Adding Custom Payment Gateways
To add a custom payment gateway, you need to:
Add a new payment controller under
app/controllers/paymentsthat will:Handle incoming payment notification from custom payment gateway
Verify the payment and its authenticity
Add a record to the
tn_paymentsdatabase with at least the following fields:payment_id: Unique ID for the payment. This can be the payment ID from the payment gateway.uid: Firebase UID of the user making the payment.amount: The amount of the payment in USD cents. Use a negative amount for refunds.gateway: The name of the payment gateway.is_synced: Should be set tofalse. A boolean flag to indicate if the payment has been synced with the Retail API.
Field constraints can be found in the
createCustomerTransactionendpoint of the Retail API.
Add a new route in in
start/routes.tsto point to the new payment controller.Add the necessary configuration variables to the
start/env.tsfile.Configure the custom payment gateway to send payment notifications to the new route.
Configure any necessary environment variables and secrets during the Temp-Number Backend installation.
Redeploy the Temp-Number Backend.