logo
Core Concepts

Payments

A Payment object represents a single attempt to move money. It transitions through a small set of states — from creation through capture, refund, or failure.

Lifecycle

  1. requires_source — created without a payment method
  2. requires_confirmation — has a source, awaiting confirmation
  3. processing — submitted to the network
  4. succeeded — funds captured
  5. failed — terminal failure (see Errors)

Creating a payment

const payment = await ypp.payments.create({
  amount: 125000,        // ₹1,250.00
  currency: "inr",
  source: "ypp_src_upi_8h2k",
  capture: true,         // false = authorize only
  metadata: { order_id: "ord_91" },
});

Capturing later

Pass capture: false to place a hold on the funds. You then have 7 days to capture, after which the authorization is automatically released.

await ypp.payments.capture(payment.id);

Refunds

Refunds can be partial or full. Funds are returned to the original payment method on the same settlement schedule as the original charge.

await ypp.refunds.create({
  payment: "pay_8Hk9bLp",
  amount: 50000, // optional, defaults to full
});