jera_payment 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +2 -0
- data/app/controllers/jera_payment/callbacks_controller.rb +22 -0
- data/app/controllers/jera_payment/jera_payment_controller.rb +5 -0
- data/config/locale/jera_payment.pt-BR.yml +243 -0
- data/config/routes.rb +5 -0
- data/lib/generators/active_record/jera_payment_generator.rb +59 -0
- data/lib/generators/active_record/templates/create_jera_payment_charges.rb +36 -0
- data/lib/generators/active_record/templates/create_jera_payment_credit_cards.rb +20 -0
- data/lib/generators/active_record/templates/create_jera_payment_customers.rb +22 -0
- data/lib/generators/active_record/templates/create_jera_payment_households.rb +18 -0
- data/lib/generators/active_record/templates/create_jera_payment_invoices.rb +42 -0
- data/lib/generators/active_record/templates/create_jera_payment_plans.rb +18 -0
- data/lib/generators/active_record/templates/create_jera_payment_sub_accounts.rb +39 -0
- data/lib/generators/active_record/templates/create_jera_payment_subscriptions.rb +26 -0
- data/lib/generators/active_record/templates/create_jera_payment_transfers.rb +15 -0
- data/lib/generators/active_record/templates/create_jera_payment_withdrawals.rb +15 -0
- data/lib/generators/jera_payment/install_generator.rb +68 -0
- data/lib/generators/jera_payment/jera_payment_generator.rb +46 -0
- data/lib/generators/jera_payment/templates/jera_payment.rb +9 -0
- data/lib/jera_payment.rb +39 -0
- data/lib/jera_payment/api/iugu/base.rb +55 -0
- data/lib/jera_payment/api/iugu/charge.rb +12 -0
- data/lib/jera_payment/api/iugu/customer.rb +37 -0
- data/lib/jera_payment/api/iugu/household.rb +13 -0
- data/lib/jera_payment/api/iugu/invoice.rb +55 -0
- data/lib/jera_payment/api/iugu/payment_method.rb +39 -0
- data/lib/jera_payment/api/iugu/payment_token.rb +12 -0
- data/lib/jera_payment/api/iugu/plan.rb +42 -0
- data/lib/jera_payment/api/iugu/sub_account.rb +40 -0
- data/lib/jera_payment/api/iugu/subscription.rb +72 -0
- data/lib/jera_payment/api/iugu/transfer.rb +24 -0
- data/lib/jera_payment/api/iugu/withdrawal.rb +26 -0
- data/lib/jera_payment/application.rb +79 -0
- data/lib/jera_payment/engine.rb +5 -0
- data/lib/jera_payment/models/charge.rb +30 -0
- data/lib/jera_payment/models/concerns/household_methods.rb +33 -0
- data/lib/jera_payment/models/concerns/invoice_methods.rb +42 -0
- data/lib/jera_payment/models/concerns/resource_callbacks.rb +40 -0
- data/lib/jera_payment/models/concerns/sub_account_methods.rb +18 -0
- data/lib/jera_payment/models/concerns/subscription_methods.rb +34 -0
- data/lib/jera_payment/models/concerns/transfer_methods.rb +18 -0
- data/lib/jera_payment/models/concerns/withdrawal_methods.rb +18 -0
- data/lib/jera_payment/models/credit_card.rb +16 -0
- data/lib/jera_payment/models/customer.rb +14 -0
- data/lib/jera_payment/models/household.rb +51 -0
- data/lib/jera_payment/models/invoice.rb +49 -0
- data/lib/jera_payment/models/plan.rb +16 -0
- data/lib/jera_payment/models/sub_account.rb +53 -0
- data/lib/jera_payment/models/subscription.rb +29 -0
- data/lib/jera_payment/models/transfer.rb +20 -0
- data/lib/jera_payment/models/withdrawal.rb +24 -0
- data/lib/jera_payment/parsers/iugu/charge_parser.rb +39 -0
- data/lib/jera_payment/parsers/iugu/credit_card_parser.rb +31 -0
- data/lib/jera_payment/parsers/iugu/household_parser.rb +16 -0
- data/lib/jera_payment/parsers/iugu/invoice_parser.rb +31 -0
- data/lib/jera_payment/parsers/iugu/sub_account_parser.rb +26 -0
- data/lib/jera_payment/parsers/iugu/transfer_parser.rb +15 -0
- data/lib/jera_payment/services/iugu/base.rb +23 -0
- data/lib/jera_payment/services/iugu/charges/create.rb +30 -0
- data/lib/jera_payment/services/iugu/credit_cards/create.rb +40 -0
- data/lib/jera_payment/services/iugu/credit_cards/destroy.rb +23 -0
- data/lib/jera_payment/services/iugu/credit_cards/update.rb +19 -0
- data/lib/jera_payment/services/iugu/customers/create.rb +27 -0
- data/lib/jera_payment/services/iugu/customers/destroy.rb +22 -0
- data/lib/jera_payment/services/iugu/customers/update.rb +30 -0
- data/lib/jera_payment/services/iugu/handle_callbacks/invoice/base.rb +24 -0
- data/lib/jera_payment/services/iugu/handle_callbacks/invoice/created.rb +8 -0
- data/lib/jera_payment/services/iugu/handle_callbacks/invoice/due.rb +8 -0
- data/lib/jera_payment/services/iugu/handle_callbacks/invoice/dunning_action.rb +8 -0
- data/lib/jera_payment/services/iugu/handle_callbacks/invoice/installment_released.rb +8 -0
- data/lib/jera_payment/services/iugu/handle_callbacks/invoice/payment_failed.rb +8 -0
- data/lib/jera_payment/services/iugu/handle_callbacks/invoice/refund.rb +8 -0
- data/lib/jera_payment/services/iugu/handle_callbacks/invoice/released.rb +8 -0
- data/lib/jera_payment/services/iugu/handle_callbacks/invoice/status_changed.rb +8 -0
- data/lib/jera_payment/services/iugu/handle_callbacks/referrals/bank_verification.rb +39 -0
- data/lib/jera_payment/services/iugu/handle_callbacks/referrals/base.rb +16 -0
- data/lib/jera_payment/services/iugu/handle_callbacks/referrals/verification.rb +24 -0
- data/lib/jera_payment/services/iugu/handle_callbacks/subscription/activated.rb +12 -0
- data/lib/jera_payment/services/iugu/handle_callbacks/subscription/base.rb +18 -0
- data/lib/jera_payment/services/iugu/handle_callbacks/subscription/changed.rb +12 -0
- data/lib/jera_payment/services/iugu/handle_callbacks/subscription/created.rb +12 -0
- data/lib/jera_payment/services/iugu/handle_callbacks/subscription/expired.rb +12 -0
- data/lib/jera_payment/services/iugu/handle_callbacks/subscription/renewed.rb +12 -0
- data/lib/jera_payment/services/iugu/handle_callbacks/subscription/suspended.rb +8 -0
- data/lib/jera_payment/services/iugu/handle_callbacks/withdraw_request/base.rb +16 -0
- data/lib/jera_payment/services/iugu/handle_callbacks/withdraw_request/created.rb +8 -0
- data/lib/jera_payment/services/iugu/handle_callbacks/withdraw_request/status_changed.rb +20 -0
- data/lib/jera_payment/services/iugu/households/create.rb +19 -0
- data/lib/jera_payment/services/iugu/invoices/create.rb +31 -0
- data/lib/jera_payment/services/iugu/invoices/duplicate.rb +54 -0
- data/lib/jera_payment/services/iugu/invoices/send_email.rb +18 -0
- data/lib/jera_payment/services/iugu/invoices/update_status.rb +31 -0
- data/lib/jera_payment/services/iugu/plans/create.rb +26 -0
- data/lib/jera_payment/services/iugu/plans/destroy.rb +17 -0
- data/lib/jera_payment/services/iugu/plans/update.rb +18 -0
- data/lib/jera_payment/services/iugu/sub_accounts/create.rb +26 -0
- data/lib/jera_payment/services/iugu/sub_accounts/update.rb +19 -0
- data/lib/jera_payment/services/iugu/sub_accounts/verify.rb +38 -0
- data/lib/jera_payment/services/iugu/subscriptions/change_plan.rb +41 -0
- data/lib/jera_payment/services/iugu/subscriptions/create.rb +29 -0
- data/lib/jera_payment/services/iugu/subscriptions/destroy.rb +26 -0
- data/lib/jera_payment/services/iugu/subscriptions/update.rb +18 -0
- data/lib/jera_payment/services/iugu/subscriptions/update_credits.rb +37 -0
- data/lib/jera_payment/services/iugu/subscriptions/update_situation.rb +36 -0
- data/lib/jera_payment/services/iugu/transfers/create.rb +28 -0
- data/lib/jera_payment/services/iugu/withdrawals/create.rb +27 -0
- data/lib/jera_payment/version.rb +3 -0
- metadata +208 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
class CreateJeraPaymentHouseholds < ActiveRecord::Migration<%= migration_version %>
|
2
|
+
def change
|
3
|
+
create_table :jera_payment_households do |t|
|
4
|
+
|
5
|
+
t.references :sub_account
|
6
|
+
t.string :agency
|
7
|
+
t.string :account
|
8
|
+
t.integer :account_type
|
9
|
+
t.integer :bank
|
10
|
+
t.string :document
|
11
|
+
t.integer :status
|
12
|
+
t.string :feedback
|
13
|
+
t.boolean :verification, default: false
|
14
|
+
|
15
|
+
t.timestamps null: false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class CreateJeraPaymentInvoices < ActiveRecord::Migration<%= migration_version %>
|
2
|
+
def change
|
3
|
+
create_table :jera_payment_invoices do |t|
|
4
|
+
|
5
|
+
t.string :api_id
|
6
|
+
t.belongs_to :customer
|
7
|
+
t.belongs_to :sub_account
|
8
|
+
t.integer :status
|
9
|
+
t.string :email
|
10
|
+
t.string :cc_emails
|
11
|
+
t.string :due_date
|
12
|
+
t.boolean :ensure_workday_due_date
|
13
|
+
t.text :items
|
14
|
+
t.integer :total_cents
|
15
|
+
t.integer :discount_cents
|
16
|
+
t.string :payable_with
|
17
|
+
t.string :return_url
|
18
|
+
t.string :expired_url
|
19
|
+
t.string :notification_url
|
20
|
+
t.boolean :fines
|
21
|
+
t.string :late_payment_fine
|
22
|
+
t.boolean :per_day_interest
|
23
|
+
t.boolean :ignore_due_email, default: false
|
24
|
+
t.boolean :ignore_canceled_email
|
25
|
+
t.boolean :current_fines_option
|
26
|
+
t.boolean :keep_early_payment_discount
|
27
|
+
t.string :subscription_api_id
|
28
|
+
t.integer :credits
|
29
|
+
t.boolean :early_payment_discount, default: false
|
30
|
+
t.text :early_payment_discounts
|
31
|
+
t.text :payer
|
32
|
+
t.string :paid_at
|
33
|
+
t.string :secure_url
|
34
|
+
t.string :digitable_line
|
35
|
+
t.string :barcode_data
|
36
|
+
t.string :barcode
|
37
|
+
t.boolean :duplicated, default: false
|
38
|
+
|
39
|
+
t.timestamps null: false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CreateJeraPaymentPlans < ActiveRecord::Migration<%= migration_version %>
|
2
|
+
def change
|
3
|
+
create_table :jera_payment_plans do |t|
|
4
|
+
|
5
|
+
t.string :api_id
|
6
|
+
t.string :name
|
7
|
+
t.string :identifier
|
8
|
+
t.integer :interval
|
9
|
+
t.string :interval_type
|
10
|
+
t.integer :value_cents
|
11
|
+
t.string :payable_with
|
12
|
+
t.text :features
|
13
|
+
t.references :sub_account
|
14
|
+
|
15
|
+
t.timestamps null: false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class CreateJeraPaymentSubAccounts < ActiveRecord::Migration<%= migration_version %>
|
2
|
+
def change
|
3
|
+
create_table :jera_payment_sub_accounts do |t|
|
4
|
+
|
5
|
+
t.references :current_household
|
6
|
+
t.references :sub_accountable, polymorphic: true, index: {name: 'index_jera_payment_sub_accounts_on_sub_accountable' }
|
7
|
+
t.string :account_id
|
8
|
+
t.string :live_api_token
|
9
|
+
t.string :test_api_token
|
10
|
+
t.string :user_token
|
11
|
+
t.string :name
|
12
|
+
t.text :comissions
|
13
|
+
t.boolean :auto_withdraw
|
14
|
+
t.boolean :fines
|
15
|
+
t.boolean :per_day_interest
|
16
|
+
t.integer :late_payment_fine
|
17
|
+
t.boolean :auto_advance
|
18
|
+
t.string :auto_advance_type
|
19
|
+
t.integer :auto_advance_option
|
20
|
+
t.text :bank_slip
|
21
|
+
t.text :credit_card
|
22
|
+
t.boolean :payment_email_notification
|
23
|
+
t.string :payment_email_notification_receiver
|
24
|
+
t.boolean :early_payment_discount
|
25
|
+
t.text :early_payment_discounts
|
26
|
+
t.integer :subscriptions_billing_days
|
27
|
+
t.integer :subscriptions_trial_period
|
28
|
+
t.string :default_return_url
|
29
|
+
t.string :owner_emails_to_notify
|
30
|
+
t.string :resp_name
|
31
|
+
t.string :resp_cpf
|
32
|
+
t.boolean :can_receive?
|
33
|
+
t.boolean :is_verified?
|
34
|
+
t.string :last_verification_request_feedback
|
35
|
+
|
36
|
+
t.timestamps null: false
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class CreateJeraPaymentSubscriptions < ActiveRecord::Migration<%= migration_version %>
|
2
|
+
def change
|
3
|
+
create_table :jera_payment_subscriptions do |t|
|
4
|
+
|
5
|
+
t.string :api_id
|
6
|
+
t.belongs_to :customer
|
7
|
+
t.string :plan_identifier
|
8
|
+
t.string :expires_at
|
9
|
+
t.boolean :only_on_charge_success
|
10
|
+
t.boolean :ignore_due_email
|
11
|
+
t.string :payable_with
|
12
|
+
t.boolean :credits_based
|
13
|
+
t.integer :price_cents
|
14
|
+
t.integer :credits_cycle
|
15
|
+
t.integer :credits_min
|
16
|
+
t.text :subitems
|
17
|
+
t.text :custom_variables
|
18
|
+
t.boolean :suspended
|
19
|
+
t.boolean :active
|
20
|
+
t.boolean :skip_charge
|
21
|
+
t.string :credits
|
22
|
+
|
23
|
+
t.timestamps null: false
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateJeraPaymentTransfers < ActiveRecord::Migration<%= migration_version %>
|
2
|
+
def change
|
3
|
+
create_table :jera_payment_transfers do |t|
|
4
|
+
|
5
|
+
t.string :api_id
|
6
|
+
t.references :sub_account
|
7
|
+
t.references :receiver
|
8
|
+
t.integer :amount_cents
|
9
|
+
t.string :amount_localized
|
10
|
+
t.text :custom_variables
|
11
|
+
|
12
|
+
t.timestamps null: false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateJeraPaymentWithdrawals < ActiveRecord::Migration<%= migration_version %>
|
2
|
+
def change
|
3
|
+
create_table :jera_payment_withdrawals do |t|
|
4
|
+
|
5
|
+
t.string :api_id
|
6
|
+
t.float :amount
|
7
|
+
t.text :custom_variables
|
8
|
+
t.integer :status
|
9
|
+
t.string :feedback
|
10
|
+
t.references :sub_account
|
11
|
+
|
12
|
+
t.timestamps null: false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
module JeraPayment
|
4
|
+
module Generators
|
5
|
+
|
6
|
+
class InstallGenerator < Rails::Generators::Base
|
7
|
+
source_root File.expand_path("../templates", __FILE__)
|
8
|
+
|
9
|
+
def initializer_file
|
10
|
+
template 'jera_payment.rb', 'config/initializers/jera_payment.rb'
|
11
|
+
end
|
12
|
+
|
13
|
+
def locale_file
|
14
|
+
copy_file '../../../../config/locale/jera_payment.pt-BR.yml', 'config/locales/jera_payment.pt-BR.yml'
|
15
|
+
end
|
16
|
+
|
17
|
+
def generate_migrations
|
18
|
+
case self.behavior
|
19
|
+
when :invoke
|
20
|
+
generate "active_record:jera_payment", "migration"
|
21
|
+
when :revoke
|
22
|
+
Rails::Generators.invoke "active_record:jera_payment", ["migration"], behavior: :revoke
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def callback_services
|
27
|
+
copy_subscription_files
|
28
|
+
copy_invoice_files
|
29
|
+
copy_sub_account_files
|
30
|
+
copy_withdrawal_files
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
def copy_subscription_files
|
35
|
+
files = ['base', 'activated', 'changed', 'created', 'expired', 'renewed', 'suspended']
|
36
|
+
|
37
|
+
files.each do |file|
|
38
|
+
copy_file "../../../jera_payment/services/iugu/handle_callbacks/subscription/#{file}.rb", "app/services/iugu/handle_callbacks/subscription/#{file}.rb"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def copy_invoice_files
|
43
|
+
files = ['base', 'created', 'due', 'dunning_action', 'installment_released', 'payment_failed', 'refund', 'released', 'status_changed']
|
44
|
+
|
45
|
+
files.each do |file|
|
46
|
+
copy_file "../../../jera_payment/services/iugu/handle_callbacks/invoice/#{file}.rb", "app/services/iugu/handle_callbacks/invoice/#{file}.rb"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def copy_sub_account_files
|
51
|
+
files = ['base', 'verification', 'bank_verification']
|
52
|
+
|
53
|
+
files.each do |file|
|
54
|
+
copy_file "../../../jera_payment/services/iugu/handle_callbacks/referrals/#{file}.rb", "app/services/iugu/handle_callbacks/referrals/#{file}.rb"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def copy_withdrawal_files
|
59
|
+
files = ['base', 'created', 'status_changed']
|
60
|
+
|
61
|
+
files.each do |file|
|
62
|
+
copy_file "../../../jera_payment/services/iugu/handle_callbacks/withdraw_request/#{file}.rb", "app/services/iugu/handle_callbacks/withdraw_request/#{file}.rb"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
class JeraPaymentGenerator < Rails::Generators::NamedBase
|
2
|
+
desc "This generator creates an initializer file at config/initializers"
|
3
|
+
source_root File.expand_path("../templates", __FILE__)
|
4
|
+
|
5
|
+
MissingModel = Class.new(Thor::Error)
|
6
|
+
|
7
|
+
def generate_relation
|
8
|
+
unless model_exists?
|
9
|
+
raise MissingModel,
|
10
|
+
"\n\tModel \"#{file_name.titlecase}\" doesn't exists. Please, create your Model and try again."
|
11
|
+
end
|
12
|
+
|
13
|
+
unless args.present?
|
14
|
+
raise MissingModel,
|
15
|
+
"\n\tYou need to pass an JeraPayment Model (Customer or/and SubAccount)"
|
16
|
+
end
|
17
|
+
|
18
|
+
args.each do |arg|
|
19
|
+
inject_into_file model_path, "\n\thas_one :#{arg.underscore}, as: :#{polymorfic_model_name(arg)}, class_name: 'JeraPayment::#{arg}'", after: '< ActiveRecord::Base'
|
20
|
+
|
21
|
+
inject_into_file model_path, "\n\thas_one :#{arg.underscore}, as: :#{polymorfic_model_name(arg)}, class_name: 'JeraPayment::#{arg}'", after: '< ApplicationRecord'
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def model_exists?
|
29
|
+
File.exist?(File.join(destination_root, model_path))
|
30
|
+
end
|
31
|
+
|
32
|
+
def model_path
|
33
|
+
@model_path ||= File.join("app", "models", "#{file_path}.rb")
|
34
|
+
end
|
35
|
+
|
36
|
+
def polymorfic_model_name(arg)
|
37
|
+
case arg
|
38
|
+
when "Customer"
|
39
|
+
return "customerable"
|
40
|
+
when "SubAccount"
|
41
|
+
return "sub_accountable"
|
42
|
+
end
|
43
|
+
|
44
|
+
raise MissingModel, "\n\tJera Payment Model \"#{arg}\" doesn't exists. Available models: Customer and SubAccount"
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
#this is the intilizer
|
2
|
+
#here you will set up the jera payment configuration
|
3
|
+
JeraPayment.setup do |config|
|
4
|
+
config.api = 'YOUR_API' # :pagar_me, :iugu, :mercado_pago
|
5
|
+
config.api_key = 'YOUR_PRODUCTION_API_KEY' # string
|
6
|
+
config.api_key_test = 'YOUR_DEVELOPMENT_API_KEY' # string
|
7
|
+
config.account_id = 'YOUR_API_ACCOUNT_ID' # string
|
8
|
+
config.is_test = 'TRUE_OF_FALSE' # boolean
|
9
|
+
end
|
data/lib/jera_payment.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'jera_payment/application'
|
2
|
+
|
3
|
+
module JeraPayment
|
4
|
+
|
5
|
+
autoload :Customer, 'jera_payment/models/customer.rb'
|
6
|
+
autoload :CreditCard, 'jera_payment/models/credit_card.rb'
|
7
|
+
autoload :Invoice, 'jera_payment/models/invoice.rb'
|
8
|
+
autoload :Charge, 'jera_payment/models/charge.rb'
|
9
|
+
autoload :Plan, 'jera_payment/models/plan.rb'
|
10
|
+
autoload :Subscription, 'jera_payment/models/subscription.rb'
|
11
|
+
autoload :SubAccount, 'jera_payment/models/sub_account.rb'
|
12
|
+
autoload :Withdrawal, 'jera_payment/models/withdrawal.rb'
|
13
|
+
autoload :Household, 'jera_payment/models/household.rb'
|
14
|
+
|
15
|
+
mattr_accessor :api
|
16
|
+
@@api = nil
|
17
|
+
|
18
|
+
mattr_accessor :api_key
|
19
|
+
@@api_key = nil
|
20
|
+
|
21
|
+
mattr_accessor :api_key_test
|
22
|
+
@@api_key_test = nil
|
23
|
+
|
24
|
+
mattr_accessor :account_id
|
25
|
+
@@account_id = nil
|
26
|
+
|
27
|
+
mattr_accessor :is_test
|
28
|
+
@@is_test = nil
|
29
|
+
|
30
|
+
def self.setup
|
31
|
+
yield self
|
32
|
+
end
|
33
|
+
|
34
|
+
@iugu_base_url = 'https://api.iugu.com/v1'
|
35
|
+
|
36
|
+
def self.iugu_base_url
|
37
|
+
@iugu_base_url
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'json'
|
3
|
+
require 'httparty'
|
4
|
+
|
5
|
+
module JeraPayment
|
6
|
+
module Api
|
7
|
+
module Iugu
|
8
|
+
class Base
|
9
|
+
|
10
|
+
def self.get(endpoint, query, account_access_token)
|
11
|
+
response = HTTParty.get("#{JeraPayment.iugu_base_url}/#{endpoint}", headers: set_headers(account_access_token), query: query)
|
12
|
+
parse_response(response)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.post(endpoint, body, account_access_token)
|
16
|
+
response = HTTParty.post("#{JeraPayment.iugu_base_url}/#{endpoint}", headers: set_headers(account_access_token), body: body.to_json)
|
17
|
+
parse_response(response)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.put(endpoint, body, account_access_token)
|
21
|
+
response = HTTParty.put("#{JeraPayment.iugu_base_url}/#{endpoint}", headers: set_headers(account_access_token), body: body.to_json)
|
22
|
+
parse_response(response)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.delete(endpoint, account_access_token)
|
26
|
+
response = HTTParty.delete("#{JeraPayment.iugu_base_url}/#{endpoint}", headers: set_headers(account_access_token))
|
27
|
+
parse_response(response)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.set_headers(account_access_token)
|
31
|
+
return { 'Content-Type': 'application/json', 'Authorization': "Basic #{Base64.encode64(ensure_account_access_token(account_access_token))}" }
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.ensure_account_access_token(account_access_token)
|
35
|
+
if account_access_token.nil?
|
36
|
+
account_access_token = JeraPayment.is_test ? JeraPayment.api_key_test : JeraPayment.api_key
|
37
|
+
else
|
38
|
+
account_access_token
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.parse_response(response)
|
43
|
+
if response.parsed_response.is_a?(Array) && response.parsed_response.first.is_a?(Hash)
|
44
|
+
response.parsed_response.map(&:deep_symbolize_keys)
|
45
|
+
elsif response.parsed_response.is_a?(Hash)
|
46
|
+
response.parsed_response.deep_symbolize_keys
|
47
|
+
else
|
48
|
+
response.parsed_response
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module JeraPayment
|
2
|
+
module Api
|
3
|
+
module Iugu
|
4
|
+
class Customer < Base
|
5
|
+
|
6
|
+
BASE_ENDPOINT = 'customers'
|
7
|
+
|
8
|
+
def self.index(query = nil, access_token = nil)
|
9
|
+
response = get(BASE_ENDPOINT, query, access_token)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.show(id, access_token = nil)
|
13
|
+
url = "#{BASE_ENDPOINT}/#{id}"
|
14
|
+
|
15
|
+
response = get(url, nil, access_token)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.create(body = {}, access_token = nil)
|
19
|
+
response = post(BASE_ENDPOINT, body, access_token)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.update(id, body = {}, access_token = nil)
|
23
|
+
url = "#{BASE_ENDPOINT}/#{id}"
|
24
|
+
|
25
|
+
response = put(url, body, access_token)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.destroy(id, access_token = nil)
|
29
|
+
url = "#{BASE_ENDPOINT}/#{id}"
|
30
|
+
|
31
|
+
response = delete(url, access_token)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|