TPaga Service
TPaga Service gem provides the functionality to call the multiple services of the TPaga platform.
Installation
To install as a gem in your environment type in your console:
gem install tpaga_service
If you want to use in your rails application, add to your Gemfile:
gem 'tpaga_service'
And run from your application directory:
bundle install
Configuration
If you are going to run tpaga in a rails environment add to the environment file (ex: environments/development.rb
) the following lines:
config.schema = 'https'
config.host = 'sandbox.tpaga.co'
config.base_path = '/api'
config.private_api_key = 'd13fr8n7vhvkuch3lq2ds5qhjnd2pddw2'
config.public_api_key = 'e8tbtu6bdi1jts34h2ktdipschq9heq0a'
using the respective api key for your TPaga user account.
Next add the the file tpaga_service.rb
to the rails initializers (ex: initializers/tpaga_service.rb
) with he following lines:
require 'tpaga_service'
TpagaService::Swagger.configure do |config|
config.scheme = Rails.application.config.tpaga_schema
config.host = Rails.application.config.tpaga_host
config.base_path = Rails.application.config.tpaga_base_path
config.private_api_key = Rails.application.config.tpaga_private_api_key
config.public_api_key = Rails.application.config.tpaga_public_api_key
config.inject_format = false
end
if you are not using rails, just simply initialize the service with the lines in the tpaga initializer before you call any service of the api.
Managing customers
You can create a customer:
require 'tpaga_service'
customer = {
firstName: 'foo',
lastName: 'bar',
email: 'foo@bar.com',
phone: '0000000000',
gender: 'M'
}
customer = TpagaService::CustomerApi.create_customer customer
customer.id
Get a customer by it's id:
customer = TpagaService::CustomerApi.get_customer_by_id 'id'
Delete a customer by it's id:
response = TpagaService::CustomerApi.delete_customer_by_id 'customer_id'
Managing credit cards
You can add a credit card to existing customers:
credit_card_create = {
primaryAccountNumber: '4111111111111111',
expirationMonth: '08',
expirationYear: '2023',
cardVerificationCode: '789',
cardHolderName: 'Jon Snow'
}
credit_card = TpagaService::CreditCardApi.add_credit_card credit_card_create, 'customer_id'
you can get the credit card of customers (NOT AVAILABLE):
credit_card = TpagaService::CreditCardApi.get_credit_card_by_id 'customer_id', 'credit_card_id'
You can delete the credit card of customers:
TpagaService::CreditCardApi.delete_credit_card_by_id 'customer_id', 'credit_card_id'
You can charge a credit card:
charge = {
amount: 10000,
taxAmount: 10000 * 0.1,
currency: 'COP',
orderId: 'Your identifier for the order',
installments: 1,
description: 'A new leash for ghost',
creditCard: 'credit_card_id'
}
charge = TpagaService::CreditCardApi.add_credit_card_charge charge
Retrieve a charge by it's id (NOT AVAILABLE):
charge = TpagaService::CreditCardApi.get_credit_card_charge_by_id 'charge_id'