Skip to main content

AbacatePay Ruby

Official AbacatePay SDK - Accept payments in seconds with a simple integration.

Instalação

Usando Gemfile

Adicione esta linha ao Gemfile da sua aplicação:
gem 'abacatepay-ruby'
E então execute:
bundle install

Instalação direta

Ou instale diretamente:
gem install abacatepay-ruby

Configuração

Configure seu token de API e ambiente em um inicializador:
# config/initializers/abacatepay.rb
AbacatePay.configure do |config|
  config.api_token = ENV['ABACATEPAY_TOKEN']
  config.environment = :sandbox # ou :production
end
⚠️ Nunca faça commit dos seus tokens de API no controle de versão. Use variáveis de ambiente.

Quick Usage

require 'abacatepay'

# Configure o token de API e ambiente
AbacatePay.configure do |config|
  config.api_token = 'your_api_key'
  config.environment = :sandbox
end

# Inicialize o cliente de billing
billing_client = AbacatePay::Clients::BillingClient.new

Criando uma Cobrança

billing_client = AbacatePay::Clients::BillingClient.new

# Criando uma Cobrança Única
billing = billing_client.create(
  AbacatePay::Resources::Billing.new(
    frequency: AbacatePay::Enums::Billing::Frequencies::ONE_TIME,
    methods: [AbacatePay::Enums::Billing::Methods::PIX],
    products: [
      AbacatePay::Resources::Billing::Product.new(
        external_id: 'PRO-PLAN',
        name: 'Pro plan',
        description: 'Pro plan subscription',
        quantity: 1,
        price: 1000 # Preço em centavos
      )
    ],
    metadata: AbacatePay::Resources::Billing::Metadata.new(
      return_url: 'https://yoursite.com/app',
      completion_url: 'https://yoursite.com/payment/success'
    ),
    customer: AbacatePay::Resources::Customer.new(
      metadata: AbacatePay::Resources::Customer::Metadata.new(
        name: 'Customer Name',
        cellphone: '11999999999',
        email: 'customer@example.com',
        tax_id: '09240529020'
      )
    )
  )
)

puts billing.url # URL de pagamento para seu cliente

Response

{
    "id": "bill_12345667",
    "url": "https://abacatepay.com/pay/bill_12345667",  # URL de pagamento para seu cliente
    "amount": 1000,
    "status": "PENDING",
    "devMode": true,
    "methods": ["PIX"],
    "frequency": "ONE_TIME",
    "nextBilling": null,
    "customer": {
        "id": "cust_12345",
        "metadata": {
            "email": "customer@example.com"
        }
    },
    "createdAt": "2024-11-04T18:38:28.573",
    "updatedAt": "2024-11-04T18:38:28.573"
}