Module: NOWPayments::API::Payments

Included in:
Client
Defined in:
lib/nowpayments/api/payments.rb

Overview

Payment-related endpoints

Instance Method Summary collapse

Instance Method Details

#create_payment(price_amount:, price_currency:, pay_currency:, pay_amount: nil, order_id: nil, order_description: nil, ipn_callback_url: nil, payout_address: nil, payout_currency: nil, payout_extra_id: nil, is_fixed_rate: nil, is_fee_paid_by_user: nil) ⇒ Hash

Create a new payment POST /v1/payment

Parameters:

  • price_amount (Numeric)

    Fiat amount

  • price_currency (String)

    Fiat currency

  • pay_currency (String)

    Crypto currency customer pays with

  • pay_amount (Numeric, nil) (defaults to: nil)

    Optional crypto amount (alternative to price_amount)

  • order_id (String, nil) (defaults to: nil)

    Optional merchant order ID

  • order_description (String, nil) (defaults to: nil)

    Optional description

  • ipn_callback_url (String, nil) (defaults to: nil)

    Optional webhook URL

  • payout_address (String, nil) (defaults to: nil)

    Optional custom payout address

  • payout_currency (String, nil) (defaults to: nil)

    Required if payout_address set

  • payout_extra_id (String, nil) (defaults to: nil)

    Optional extra ID for payout

  • is_fixed_rate (Boolean, nil) (defaults to: nil)

    Fixed rate flag

  • is_fee_paid_by_user (Boolean, nil) (defaults to: nil)

    Whether user pays network fees

Returns:

  • (Hash)

    Payment details



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/nowpayments/api/payments.rb', line 22

def create_payment(
  price_amount:,
  price_currency:,
  pay_currency:,
  pay_amount: nil,
  order_id: nil,
  order_description: nil,
  ipn_callback_url: nil,
  payout_address: nil,
  payout_currency: nil,
  payout_extra_id: nil,
  is_fixed_rate: nil,
  is_fee_paid_by_user: nil
)
  params = {
    price_amount: price_amount,
    price_currency: price_currency,
    pay_currency: pay_currency
  }

  params[:pay_amount] = pay_amount if pay_amount
  params[:order_id] = order_id if order_id
  params[:order_description] = order_description if order_description
  params[:ipn_callback_url] = ipn_callback_url if ipn_callback_url
  params[:payout_address] = payout_address if payout_address
  params[:payout_currency] = payout_currency if payout_currency
  params[:payout_extra_id] = payout_extra_id if payout_extra_id
  params[:is_fixed_rate] = is_fixed_rate unless is_fixed_rate.nil?
  params[:is_fee_paid_by_user] = is_fee_paid_by_user unless is_fee_paid_by_user.nil?

  validate_payment_params!(params)

  post("payment", body: params).body
end

#payment(payment_id) ⇒ Hash

Get payment status GET /v1/payment/:payment_id

Parameters:

  • payment_id (Integer, String)

    Payment ID

Returns:

  • (Hash)

    Payment status



61
62
63
# File 'lib/nowpayments/api/payments.rb', line 61

def payment(payment_id)
  get("payment/#{payment_id}").body
end

#payments(limit: 10, page: 0, sort_by: nil, order_by: nil, date_from: nil, date_to: nil) ⇒ Hash

List payments with pagination and filters GET /v1/payment

Parameters:

  • limit (Integer) (defaults to: 10)

    Results per page

  • page (Integer) (defaults to: 0)

    Page number

  • sort_by (String, nil) (defaults to: nil)

    Sort field

  • order_by (String, nil) (defaults to: nil)

    Order direction (asc/desc)

  • date_from (String, nil) (defaults to: nil)

    Start date filter

  • date_to (String, nil) (defaults to: nil)

    End date filter

Returns:

  • (Hash)

    List of payments



74
75
76
77
78
79
80
81
82
# File 'lib/nowpayments/api/payments.rb', line 74

def payments(limit: 10, page: 0, sort_by: nil, order_by: nil, date_from: nil, date_to: nil)
  params = { limit: limit, page: page }
  params[:sortBy] = sort_by if sort_by
  params[:orderBy] = order_by if order_by
  params[:dateFrom] = date_from if date_from
  params[:dateTo] = date_to if date_to

  get("payment", params: params).body
end

#update_payment_estimate(payment_id) ⇒ Hash

Update payment estimate PATCH /v1/payment/:payment_id

Parameters:

  • payment_id (Integer, String)

    Payment ID

Returns:

  • (Hash)

    Updated payment



88
89
90
# File 'lib/nowpayments/api/payments.rb', line 88

def update_payment_estimate(payment_id)
  patch("payment/#{payment_id}").body
end