Polar

Setup

1

Get your Polar credentials.

To use Dodo Payments, you need an API key. You can get them from the Polar Dashboard.

2

Configure the provider.

To configure the provider

import { BetterPay } from "better-pay"

const provider = new BetterPay({
    provider: 'polar',
    accessToke: 'YOUR_ACCESS_TOKEN'
})  

Usage

To implement the complete payment flow. Checkout this demo app.

Create payment

To create payment with polar, you can use the createPayment function provided by the provider. It takes object with following properties:

Properties
  1. Name

  2. Amount

  3. Currency

  4. Metadata (optional)

import { BetterPay } from "better-pay"

const provider = new BetterPay({
    provider: 'polar',
    accessToke: 'YOUR_ACCESS_TOKEN'
})  

const response = await provider.createPayment({
    name: 'NAME_OF_PRODUCT',
    amount: 10000,
    currency: 'usd',
    organizationId: 'YOUR_ORGANIZATION_ID', // optional
    metadata: {} // optional
})
Response
  1. Product Id

  2. Type


Confirm payment

To confirm payment with polar, you can use the confirmPayment function provided by the provider. It takes object with following properties:

Properties
  1. Product Id

  2. Return Url

import { BetterPay } from "better-pay"

const provider = new BetterPay({
    provider: 'polar',
    accessToke: 'YOUR_ACCESS_TOKEN'
})  

const response = await provider.confirmPayment({
      productId: ['PRODUCT_ID'], // You can add more product id's seperated by comma.
      returnUrl: 'YOUR_RETURN_URL_AFTER_SUCCESSFULL_PAYMENT'
})
Response
  1. Client Secret

  2. Payment Link (use this link to make payment)

  3. Type

Last updated