Project

payjpv2

0.0
No release in over 3 years
A Ruby client library for the PAY.JP v2 API
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 3.6, >= 3.6.0

Runtime

~> 1.0, >= 1.0.1
 Project Readme

payjpv2

A Ruby client library for the PAY.JP v2 API. This SDK provides a convenient way to interact with PAY.JP's payment processing services from Ruby applications.

This Ruby gem is automatically generated by the OpenAPI Generator project:

  • API version: 2.0.0
  • Package version: 1.0.7
  • Generator version: 7.14.0
  • Build package: org.openapitools.codegen.languages.RubyClientCodegen

Requirements

Ruby 3.2+

Installation & Usage

Install from RubyGems

gem install payjpv2

Using Bundler

Add this line to your application's Gemfile:

gem 'payjpv2', '~> 1.0.7'

Then execute:

bundle install

Install from Git

If you want to use the latest development version, add this to your Gemfile:

gem 'payjpv2', git: 'https://github.com/payjp/payjpv2-ruby.git'

Then import the package:

require 'payjpv2'

Getting Started

Please follow the installation procedure and then run the following:

require 'payjpv2'
require 'securerandom'

# Configure Bearer authentication with API key
# You can set your API key via environment variable or directly in code
PAYJPv2.configure do |config|
  config.access_token = ENV['PAYJP_API_KEY']
end

# Create API instance
customers_api = PAYJPv2::CustomersApi.new

begin
  # Create a customer with idempotency key
  customer_request = PAYJPv2::CustomerCreateRequest.new(
    email: 'customer@example.com',
    description: 'Test customer'
  )

  idempotency_key = SecureRandom.uuid
  customer = customers_api.create_customer(
    customer_request,
    idempotency_key: idempotency_key
  )
  puts "Created customer: #{customer.id}"
  puts "Email: #{customer.email}"

  # Retrieve a customer
  retrieved = customers_api.get_customer(customer.id)
  puts "Retrieved customer: #{retrieved.id}"

  # List customers with pagination
  customer_list = customers_api.get_all_customers(limit: 10)
  customer_list.data.each do |c|
    puts "  - #{c.id} (#{c.email || 'no email'})"
  end

rescue PAYJPv2::ApiError => e
  puts "API Error: #{e.message}"
  puts "HTTP status code: #{e.code}" if e.code
end

Configuration

Environment Variables

For security, it's recommended to store your API key in environment variables:

export PAYJP_API_KEY=sk_test_xxxxxxxxxxxx

Configuration Options

PAYJPv2.configure do |config|
  # API Host (optional, defaults to https://api.pay.jp)
  config.host = 'https://api.pay.jp'

  # Bearer authentication (recommended)
  config.access_token = ENV['PAYJP_API_KEY']

  # Or use a proc to dynamically fetch the token
  config.access_token_getter = -> { fetch_token_from_secure_storage }
end

Idempotency Keys

PAY.JP supports idempotency keys to safely retry requests without accidentally performing the same operation twice:

require 'securerandom'

idempotency_key = SecureRandom.uuid
customer = customers_api.create_customer(
  customer_request,
  idempotency_key: idempotency_key
)

Accessing HTTP Response Details

By default, API methods return only the response data. If you need access to the HTTP status code and headers, use the include_http_info option:

# Default: returns data only
customer = customers_api.get_customer('cus_xxxxx')

# With include_http_info: returns [data, status_code, headers]
data, status_code, headers = customers_api.get_customer(
  'cus_xxxxx',
  include_http_info: true
)

puts "Status: #{status_code}"        # => 200
puts "Headers: #{headers}"           # => { "Content-Type" => "application/json", ... }
puts "Customer ID: #{data.id}"       # => "cus_xxxxx"

Error Handling

The SDK raises PAYJPv2::ApiError exceptions for API errors:

begin
  customer = customers_api.create_customer(customer_request)
rescue PAYJPv2::ApiError => e
  puts "Error: #{e.message}"
  puts "Status code: #{e.code}" if e.code
  puts "Response body: #{e.response_body}" if e.response_body
  puts "Response headers: #{e.response_headers}" if e.response_headers
end

Available Error Attributes

  • e.message - Error message
  • e.code - HTTP status code
  • e.response_body - Raw response body
  • e.response_headers - Response headers

Common HTTP Status Codes

  • 400 - Invalid request parameters
  • 401 - Authentication error (invalid API key)
  • 403 - Permission error
  • 404 - Resource not found
  • 429 - Rate limit exceeded
  • 500 - Internal server error

Documentation for API Endpoints

All URIs are relative to http://localhost

Class Method HTTP request Description
PAYJPv2::BalancesApi create_balance_url POST /v2/balances/{balance_id}/balance_urls Create Balance Url
PAYJPv2::BalancesApi get_all_balances GET /v2/balances Get All Balances
PAYJPv2::BalancesApi get_balance GET /v2/balances/{balance_id} Get Balance
PAYJPv2::CheckoutSessionsApi create_checkout_session POST /v2/checkout/sessions Create Checkout Session
PAYJPv2::CheckoutSessionsApi get_all_checkout_session_line_items GET /v2/checkout/sessions/{checkout_session_id}/line_items Get All Checkout Session Line Items
PAYJPv2::CheckoutSessionsApi get_all_checkout_sessions GET /v2/checkout/sessions Get All Checkout Sessions
PAYJPv2::CheckoutSessionsApi get_checkout_session GET /v2/checkout/sessions/{checkout_session_id} Get Checkout Session
PAYJPv2::CheckoutSessionsApi update_checkout_session POST /v2/checkout/sessions/{checkout_session_id} Update Checkout Session
PAYJPv2::CustomersApi create_customer POST /v2/customers Create Customer
PAYJPv2::CustomersApi delete_customer DELETE /v2/customers/{customer_id} Delete Customer
PAYJPv2::CustomersApi get_all_customers GET /v2/customers Get All Customers
PAYJPv2::CustomersApi get_customer GET /v2/customers/{customer_id} Get Customer
PAYJPv2::CustomersApi get_customer_payment_methods GET /v2/customers/{customer_id}/payment_methods Get Customer Payment Methods
PAYJPv2::CustomersApi update_customer POST /v2/customers/{customer_id} Update Customer
PAYJPv2::EventsApi get_all_events GET /v2/events Get All Events
PAYJPv2::EventsApi get_event GET /v2/events/{event_id} Get Event
PAYJPv2::PaymentDisputesApi get_all_payment_disputes GET /v2/payment_disputes Get All Payment Disputes
PAYJPv2::PaymentDisputesApi get_payment_dispute GET /v2/payment_disputes/{payment_dispute_id} Get Payment Dispute
PAYJPv2::PaymentFlowsApi cancel_payment_flow POST /v2/payment_flows/{payment_flow_id}/cancel Cancel Payment Flow
PAYJPv2::PaymentFlowsApi capture_payment_flow POST /v2/payment_flows/{payment_flow_id}/capture Capture Payment Flow
PAYJPv2::PaymentFlowsApi confirm_payment_flow POST /v2/payment_flows/{payment_flow_id}/confirm Confirm Payment Flow
PAYJPv2::PaymentFlowsApi create_payment_flow POST /v2/payment_flows Create Payment Flow
PAYJPv2::PaymentFlowsApi get_all_payment_flows GET /v2/payment_flows Get All Payment Flows
PAYJPv2::PaymentFlowsApi get_payment_flow GET /v2/payment_flows/{payment_flow_id} Get Payment Flow
PAYJPv2::PaymentFlowsApi get_payment_flow_refunds GET /v2/payment_flows/{payment_flow_id}/refunds Get Payment Flow Refunds
PAYJPv2::PaymentFlowsApi update_payment_flow POST /v2/payment_flows/{payment_flow_id} Update Payment Flow
PAYJPv2::PaymentMethodConfigurationsApi get_all_payment_method_configurations GET /v2/payment_method_configurations Get All Payment Method Configurations
PAYJPv2::PaymentMethodConfigurationsApi get_payment_method_configuration GET /v2/payment_method_configurations/{payment_method_configuration_id} Get Payment Method Configuration
PAYJPv2::PaymentMethodConfigurationsApi update_payment_method_configuration POST /v2/payment_method_configurations/{payment_method_configuration_id} Update Payment Method Configuration
PAYJPv2::PaymentMethodsApi attach_payment_method POST /v2/payment_methods/{payment_method_id}/attach Attach Payment Method
PAYJPv2::PaymentMethodsApi create_payment_method POST /v2/payment_methods Create Payment Method
PAYJPv2::PaymentMethodsApi detach_payment_method POST /v2/payment_methods/{payment_method_id}/detach Detach Payment Method
PAYJPv2::PaymentMethodsApi get_all_payment_methods GET /v2/payment_methods Get All Payment Methods
PAYJPv2::PaymentMethodsApi get_payment_method GET /v2/payment_methods/{payment_method_id} Get Payment Method
PAYJPv2::PaymentMethodsApi get_payment_method_by_card GET /v2/payment_methods/cards/{card_id} Get Payment Method By Card
PAYJPv2::PaymentMethodsApi update_payment_method POST /v2/payment_methods/{payment_method_id} Update Payment Method
PAYJPv2::PaymentRefundsApi create_payment_refund POST /v2/payment_refunds Create Payment Refund
PAYJPv2::PaymentRefundsApi get_all_payment_refunds GET /v2/payment_refunds Get All Payment Refunds
PAYJPv2::PaymentRefundsApi get_payment_refund GET /v2/payment_refunds/{payment_refund_id} Get Payment Refund
PAYJPv2::PaymentRefundsApi update_payment_refund POST /v2/payment_refunds/{payment_refund_id} Update Payment Refund
PAYJPv2::PaymentTransactionsApi get_all_payment_transactions GET /v2/payment_transactions Get All Payment Transactions
PAYJPv2::PaymentTransactionsApi get_payment_transaction GET /v2/payment_transactions/{payment_transaction_id} Get Payment Transaction
PAYJPv2::PricesApi create_price POST /v2/prices Create Price
PAYJPv2::PricesApi get_all_prices GET /v2/prices Get All Prices
PAYJPv2::PricesApi get_price GET /v2/prices/{price_id} Get Price
PAYJPv2::PricesApi update_price POST /v2/prices/{price_id} Update Price
PAYJPv2::ProductsApi create_product POST /v2/products Create Product
PAYJPv2::ProductsApi delete_product DELETE /v2/products/{product_id} Delete Product
PAYJPv2::ProductsApi get_all_products GET /v2/products Get All Products
PAYJPv2::ProductsApi get_product GET /v2/products/{product_id} Get Product
PAYJPv2::ProductsApi update_product POST /v2/products/{product_id} Update Product
PAYJPv2::SetupFlowsApi cancel_setup_flow POST /v2/setup_flows/{setup_flow_id}/cancel Cancel Setup Flow
PAYJPv2::SetupFlowsApi create_setup_flow POST /v2/setup_flows Create Setup Flow
PAYJPv2::SetupFlowsApi get_all_setup_flows GET /v2/setup_flows Get All Setup Flows
PAYJPv2::SetupFlowsApi get_setup_flow GET /v2/setup_flows/{setup_flow_id} Get Setup Flow
PAYJPv2::SetupFlowsApi update_setup_flow POST /v2/setup_flows/{setup_flow_id} Update Setup Flow
PAYJPv2::StatementsApi create_statement_url POST /v2/statements/{statement_id}/statement_urls Create Statement Url
PAYJPv2::StatementsApi get_all_statements GET /v2/statements Get All Statements
PAYJPv2::StatementsApi get_statement GET /v2/statements/{statement_id} Get Statement
PAYJPv2::TaxRatesApi create_tax_rate POST /v2/tax_rates Create Tax Rate
PAYJPv2::TaxRatesApi get_all_tax_rates GET /v2/tax_rates Get All Tax Rates
PAYJPv2::TaxRatesApi get_tax_rate GET /v2/tax_rates/{tax_rate_id} Get Tax Rate
PAYJPv2::TaxRatesApi update_tax_rate POST /v2/tax_rates/{tax_rate_id} Update Tax Rate
PAYJPv2::TermsApi get_all_terms GET /v2/terms Get All Terms
PAYJPv2::TermsApi get_term GET /v2/terms/{term_id} Get Term

Documentation for Models

Documentation for Authorization

Authentication schemes defined for the API:

HTTPBasic

  • Type: HTTP basic authentication

HTTPBearer

  • Type: Bearer authentication