PayGate

Payment Links

Create and manage payment links.

Payment Links API

Payment Links allow you to create shareable URLs that accept payments without writing checkout code.

{
  "id": "pl_abc123def456",
  "object": "payment_link",
  "active": true,
  "amount": 10000,
  "currency": "GHS",
  "name": "Premium Subscription",
  "description": "Monthly subscription to Premium plan",
  "url": "https://paygate.44.200.142.19.nip.io/pay/pl_abc123def456",
  "allow_custom_amount": false,
  "minimum_amount": null,
  "maximum_amount": null,
  "collect_phone": true,
  "collect_email": true,
  "collect_name": false,
  "success_url": "https://yoursite.com/success",
  "metadata": {
    "product_id": "prod_123"
  },
  "created_at": "2024-01-15T10:00:00Z"
}

Attributes

AttributeTypeDescription
idstringUnique identifier
objectstringAlways "payment_link"
activebooleanWhether link is active
amountintegerAmount in pesewas (null for custom amounts)
currencystringCurrency code
namestringLink name/title
descriptionstringDescription
urlstringShareable payment URL
allow_custom_amountbooleanAllow customer to enter amount
minimum_amountintegerMinimum amount if custom
maximum_amountintegerMaximum amount if custom
collect_phonebooleanRequire phone number
collect_emailbooleanRequire email
collect_namebooleanRequire name
success_urlstringRedirect after payment
metadataobjectCustom metadata
created_atstringCreation timestamp

Creates a new payment link.

POST /v1/payment_links

Request Body

ParameterTypeRequiredDescription
amountintegerNo*Amount in pesewas
currencystringNoCurrency (default: GHS)
namestringYesLink name
descriptionstringNoDescription
allow_custom_amountbooleanNoAllow custom amount
minimum_amountintegerNoMin amount (if custom)
maximum_amountintegerNoMax amount (if custom)
collect_phonebooleanNoRequire phone
collect_emailbooleanNoRequire email
collect_namebooleanNoRequire name
success_urlstringNoRedirect URL
expires_atstringNoExpiration timestamp
metadataobjectNoCustom metadata

Either amount or allow_custom_amount: true is required.

# Fixed amount link
curl -X POST https://api.44.200.142.19.nip.io/v1/payment_links \
  -H "Authorization: Bearer sk_test_..." \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 10000,
    "currency": "GHS",
    "name": "Premium Subscription",
    "description": "Monthly subscription to Premium plan",
    "collect_email": true,
    "success_url": "https://yoursite.com/success",
    "metadata": {
      "product_id": "prod_123"
    }
  }'

# Custom amount link (donation)
curl -X POST https://api.44.200.142.19.nip.io/v1/payment_links \
  -H "Authorization: Bearer sk_test_..." \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Donation",
    "description": "Support our cause",
    "allow_custom_amount": true,
    "minimum_amount": 100,
    "maximum_amount": 1000000,
    "collect_email": true,
    "collect_name": true
  }'
// Fixed amount link
const link = await paygate.paymentLinks.create({
  amount: 10000,
  currency: 'GHS',
  name: 'Premium Subscription',
  description: 'Monthly subscription to Premium plan',
  collect_email: true,
  success_url: 'https://yoursite.com/success',
  metadata: {
    product_id: 'prod_123'
  }
})

console.log(link.url) // https://paygate.44.200.142.19.nip.io/pay/pl_abc123

// Custom amount link (donation)
const donationLink = await paygate.paymentLinks.create({
  name: 'Donation',
  description: 'Support our cause',
  allow_custom_amount: true,
  minimum_amount: 100,
  maximum_amount: 1000000,
  collect_email: true,
  collect_name: true
})
# Fixed amount link
link = client.payment_links.create(
    amount=10000,
    currency='GHS',
    name='Premium Subscription',
    description='Monthly subscription to Premium plan',
    collect_email=True,
    success_url='https://yoursite.com/success',
    metadata={'product_id': 'prod_123'}
)

print(link.url)  # https://paygate.44.200.142.19.nip.io/pay/pl_abc123

# Custom amount link
donation_link = client.payment_links.create(
    name='Donation',
    description='Support our cause',
    allow_custom_amount=True,
    minimum_amount=100,
    maximum_amount=1000000,
    collect_email=True,
    collect_name=True
)
// Fixed amount link
$link = $paygate->paymentLinks->create([
    'amount' => 10000,
    'currency' => 'GHS',
    'name' => 'Premium Subscription',
    'description' => 'Monthly subscription to Premium plan',
    'collect_email' => true,
    'success_url' => 'https://yoursite.com/success',
    'metadata' => ['product_id' => 'prod_123']
]);

echo $link->url;

// Custom amount link
$donationLink = $paygate->paymentLinks->create([
    'name' => 'Donation',
    'description' => 'Support our cause',
    'allow_custom_amount' => true,
    'minimum_amount' => 100,
    'maximum_amount' => 1000000,
    'collect_email' => true,
    'collect_name' => true
]);

Retrieves a payment link by ID.

GET /v1/payment_links/:id
curl https://api.44.200.142.19.nip.io/v1/payment_links/pl_abc123def456 \
  -H "Authorization: Bearer sk_test_..."
const link = await paygate.paymentLinks.retrieve('pl_abc123def456')
link = client.payment_links.retrieve('pl_abc123def456')

Updates a payment link.

PATCH /v1/payment_links/:id

Request Body

ParameterTypeDescription
namestringLink name
descriptionstringDescription
activebooleanWhether link is active
success_urlstringRedirect URL
metadataobjectCustom metadata
curl -X PATCH https://api.44.200.142.19.nip.io/v1/payment_links/pl_abc123def456 \
  -H "Authorization: Bearer sk_test_..." \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Updated Product Name",
    "active": true
  }'
const link = await paygate.paymentLinks.update('pl_abc123def456', {
  name: 'Updated Product Name',
  active: true
})
link = client.payment_links.update('pl_abc123def456',
    name='Updated Product Name',
    active=True
)

Returns a list of payment links.

GET /v1/payment_links

Query Parameters

ParameterTypeDescription
limitintegerNumber of results (1-100)
starting_afterstringCursor for pagination
activebooleanFilter by active status
curl "https://api.44.200.142.19.nip.io/v1/payment_links?active=true&limit=10" \
  -H "Authorization: Bearer sk_test_..."
const links = await paygate.paymentLinks.list({
  active: true,
  limit: 10
})
links = client.payment_links.list(active=True, limit=10)

Deactivate a link to stop accepting payments:

const link = await paygate.paymentLinks.update('pl_abc123def456', {
  active: false
})

List payments made through a specific link:

const payments = await paygate.payments.list({
  payment_link: 'pl_abc123def456'
})

console.log(`Total payments: ${payments.data.length}`)

Or use webhooks:

app.post('/webhooks', (req, res) => {
  const event = Webhook.constructEvent(req.body, signature, secret)

  if (event.type === 'payment.succeeded') {
    const payment = event.data.object

    if (payment.payment_link) {
      console.log(`Payment via link: ${payment.payment_link}`)
      // Process the payment
    }
  }

  res.json({ received: true })
})