xendit-rails 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3899b263ecde063c35214087df81bf125063d294e5de2e8bb62b30a42d47b933
4
- data.tar.gz: d60cff9bce184189f73fb0e927cb997a22335cdbaa6fc9e59bd9e6e38ea657da
3
+ metadata.gz: d9e766f68f5bfdb0463c6dc08b2ed7ddc2ac3591a68a93ce1313bb424931e422
4
+ data.tar.gz: afba098d3de38edf092f7aab550925badbf920cfb628a717f730d07a9ce3a8f0
5
5
  SHA512:
6
- metadata.gz: 1a43512dd1d48ab766a8fe0c4477f0c8829fa48346e7ba7b7a83db7126232e07cecbfd85089ea1c16d789f4b01fd37284422230eb9f8bdc14fd9a3cf933323e5
7
- data.tar.gz: d680f424894ff36d7ac291e19830c26aefa72f2fba3fe90de1dfa079640a83e318b3a3484d24830e88754edbcdb9db5ffd445849bb55f0c28755fe0e2bc6a1f0
6
+ metadata.gz: 4aae8d5b504b24fd44c635f1d3206326d9d76b984131ee60d69ea6dfedf7861fa32230ae2745115aaea29161ecb0142f76e51854b08a8c0020d1eb7fe9b3424a
7
+ data.tar.gz: 54de86d3006d565353ea922ba7f195b49a26045b4947a68abaa62f416f7273a615d8c015ee2bf3f98e16f541a3bfc73130d716d97c777ab00df51db329ec0475
data/README.md CHANGED
@@ -1,42 +1,46 @@
1
1
  # Xendit Rails
2
+
2
3
  A drop in rails engine for receiving payment via xendit.
3
4
 
4
5
  ## Installation
5
- Add the gem to your Gemfile
6
- ```
6
+
7
+ ```rb
7
8
  gem 'xendit-rails', github: 'bekicot/xendit-rails'
8
9
  ```
9
10
 
10
11
  And then execute:
12
+
11
13
  ```bash
12
14
  $ bundle
15
+ Using xendit-rails 0.0.1 from https://github.com/bekicot/xendit-rails.git (at master@50ef229)
13
16
  ```
14
17
 
15
18
  Copy migration files
19
+
16
20
  ```bash
17
21
  $ bin/rails xendit:install:migrations
22
+ Copied migration 20200410225858_create_xendit_virtual_accounts.xendit.rb from xendit
23
+ Copied migration 20200410225859_create_xendit_payments.xendit.rb from xendit
18
24
  ```
19
25
 
20
26
  Mount the engine to your routes
27
+
21
28
  ```rb
22
29
  mount Xendit::Rails::Engine => 'xendit-rails'
23
30
  ```
24
31
 
25
32
  And then add the callback to your xendit account
26
- ```
27
- FVA Paid:
28
- https://yourdomain.com/xendit-rails/callbacks/virtual_accounts/paid
29
33
 
30
- FVA Created:
31
- https://yourdomain.com/xendit-rails/callbacks/virtual_accounts/
32
- ```
34
+ - FVA Paid: `https://yourdomain.com/xendit-rails/callbacks/virtual_accounts/paid`
35
+ - FVA Created: `https://yourdomain.com/xendit-rails/callbacks/virtual_accounts/`
33
36
 
34
37
  ## Support
35
- [Github Issue](https://github.com/issues)
36
- [Email Me](mailto:yana.developer@gmail.com)
37
38
 
38
- Nuhun!!
39
+ - [Github Issue](https://github.com/bekicot/xendit-rails/issues)
40
+ - [Email Me](mailto:yana.developer@gmail.com)
39
41
 
42
+ Nuhun!!
40
43
 
41
44
  ## License
45
+
42
46
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_dependency "xendit/application_controller"
4
+ require_dependency "xendit/invoice/payment_receiver"
5
+ module Xendit
6
+ class Callbacks::InvoicesController < ApplicationController
7
+ def paid_or_expired
8
+ Xendit::Invoice::PaymentReceiver.new(params).perform!
9
+ head 200
10
+ end
11
+ end
12
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_dependency 'xendit/application_controller'
3
+ require_dependency "xendit/application_controller"
4
4
 
5
5
  module Xendit::Callbacks
6
6
  class VirtualAccountsController < Xendit::ApplicationController
@@ -12,9 +12,9 @@ module Xendit::Callbacks
12
12
 
13
13
  def paid
14
14
  xendit_va = Xendit::VirtualAccount
15
- .find_or_initialize_by(
16
- id: params[:callback_virtual_account_id]
17
- )
15
+ .find_or_initialize_by(
16
+ id: params[:callback_virtual_account_id]
17
+ )
18
18
  if xendit_va.new_record?
19
19
  xendit_va.assign_attributes(virtual_account_params)
20
20
  xendit_va.save!
@@ -32,7 +32,7 @@ module Xendit::Callbacks
32
32
 
33
33
  def virtual_account_params
34
34
  @virtual_account_params = params
35
- .permit(Xendit::VirtualAccount::ATTRIBUTES)
35
+ .permit(Xendit::VirtualAccount::ATTRIBUTES)
36
36
  end
37
37
  end
38
38
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Xendit
4
4
  class ApplicationMailer < ActionMailer::Base
5
- default from: 'from@example.com'
6
- layout 'mailer'
5
+ default from: "from@example.com"
6
+ layout "mailer"
7
7
  end
8
8
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Xendit::TimestampMapable
4
+ extend ActiveSupport::Concern
5
+ included do
6
+ alias_attribute :created, :created_at
7
+ alias_attribute :updated, :updated_at
8
+ end
9
+ end
@@ -3,5 +3,13 @@
3
3
  module Xendit
4
4
  class ApplicationRecord < ActiveRecord::Base
5
5
  self.abstract_class = true
6
+
7
+ include Xendit::TimestampMapable
8
+
9
+ ATTRIBUTES = %i[created updated].freeze
10
+
11
+ def self.allowed_attributes
12
+ ATTRIBUTES + self::ATTRIBUTES
13
+ end
6
14
  end
7
15
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Xendit
4
+ class Invoice < ApplicationRecord
5
+ alias_attribute :should_exclude_credit_card, :exclude_credit_card
6
+ alias_attribute :should_send_email, :send_email
7
+ alias_attribute :recurring_payment_id, :recurring_id
8
+
9
+ ATTRIBUTES = %i[recurring_id
10
+ user_id
11
+ external_id
12
+ status
13
+ merchant_name
14
+ merchant_profile_picture_url
15
+ amount
16
+ payer_email
17
+ description
18
+ invoice_url
19
+ expiry_date
20
+ available_banks
21
+ available_retail_outlets
22
+ exclude_credit_card
23
+ send_email
24
+ mid_label
25
+ currency
26
+ paid_at
27
+ credit_card_charge_id
28
+ payment_method
29
+ payment_channel
30
+ payment_destination
31
+ success_redirect_url
32
+ failure_redirect_url
33
+ fixed_va].freeze
34
+
35
+ belongs_to :recurring, optional: true
36
+ end
37
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Xendit
4
+ class InvoicePayment < ApplicationRecord
5
+ alias_attribute :is_high, :high
6
+
7
+ ATTRIBUTES = %i[invoice_id
8
+ user_id
9
+ external_id
10
+ high
11
+ is_high
12
+ merchant_name
13
+ amount
14
+ status
15
+ payer_email
16
+ description
17
+ fees_paid_amount
18
+ adjusted_received_amount
19
+ bank_code
20
+ retail_outlet_name
21
+ ewallet_type
22
+ on_demand_link
23
+ paid_amount
24
+ mid_label
25
+ currency
26
+ success_redirect_url
27
+ failure_redirect_url
28
+ paid_at
29
+ credit_card_charge_id
30
+ payment_method
31
+ payment_channel
32
+ payment_destination].freeze
33
+ end
34
+ end
@@ -5,7 +5,8 @@ module Xendit
5
5
  alias_attribute :callback_virtual_account_id, :virtual_account_id
6
6
  alias_attribute :payment_id, :id
7
7
 
8
- ATTRIBUTES = %i[amount transaction_timestamp
8
+ ATTRIBUTES = %i[amount
9
+ transaction_timestamp
9
10
  payment_id
10
11
  callback_virtual_account_id].freeze
11
12
 
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Xendit
4
+ class Recurring < ApplicationRecord
5
+ alias_attribute :should_send_email, :send_email
6
+ ATTRIBUTES = %i[id
7
+ user_id
8
+ external_id
9
+ status
10
+ amount
11
+ payer_email
12
+ description
13
+ send_email
14
+ interval
15
+ interval_count
16
+ total_recurrence
17
+ recurrence_progress
18
+ last_created_invoice_url
19
+ credit_card_token
20
+ success_redirect_url
21
+ failure_redirect_url
22
+ invoice_duration
23
+ charge_immediately
24
+ recharge].freeze
25
+
26
+ has_many :invoices
27
+ end
28
+ end
data/config/routes.rb CHANGED
@@ -3,8 +3,11 @@
3
3
  Xendit::Rails::Engine.routes.draw do
4
4
  namespace :callbacks do
5
5
  controller :virtual_accounts do
6
- post 'virtual_accounts', action: 'update'
7
- post 'virtual_accounts/paid', action: :paid
6
+ post "virtual_accounts", action: "update"
7
+ post "virtual_accounts/paid", action: :paid
8
+ end
9
+ controller :invoices do
10
+ post "invoices/paid_or_expired", action: "paid_or_expired"
8
11
  end
9
12
  end
10
13
  end
@@ -6,8 +6,8 @@ class CreateXenditPayments < ActiveRecord::Migration[6.0]
6
6
  t.bigint :amount
7
7
  t.datetime :transaction_timestamp
8
8
  t.references :virtual_account,
9
- foreign_key: { to_table: :xendit_virtual_accounts },
10
- type: :string
9
+ foreign_key: {to_table: :xendit_virtual_accounts},
10
+ type: :string
11
11
  t.timestamps
12
12
  end
13
13
  end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateXenditInvoices < ActiveRecord::Migration[6.0]
4
+ def change
5
+ create_table :xendit_invoices, id: :string do |t|
6
+ t.string :user_id
7
+ t.string :external_id
8
+ t.string :status
9
+ t.string :merchant_name
10
+ t.string :merchant_profile_picture_url
11
+ t.bigint :amount
12
+ t.string :payer_email
13
+ t.text :description
14
+ t.string :invoice_url
15
+ t.datetime :expiry_date
16
+ t.text :available_banks
17
+ t.text :available_retail_outlets
18
+ t.boolean :exclude_credit_card
19
+ t.boolean :send_email
20
+ t.text :mid_label
21
+ t.string :currency
22
+ t.datetime :paid_at
23
+ t.string :credit_card_charge_id
24
+ t.string :payment_method
25
+ t.string :payment_channel
26
+ t.string :payment_destination
27
+ t.string :success_redirect_url
28
+ t.string :failure_redirect_url
29
+ t.string :fixed_va
30
+ t.references :recurring
31
+ t.timestamps
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateXenditInvoicePayments < ActiveRecord::Migration[6.0]
4
+ def change
5
+ create_table :xendit_invoice_payments do |t|
6
+ t.string :user_id
7
+ t.string :external_id
8
+ t.boolean :high
9
+ t.string :merchant_name
10
+ t.bigint :amount
11
+ t.string :status
12
+ t.string :payer_email
13
+ t.text :description
14
+ t.bigint :fees_paid_amount
15
+ t.bigint :adjusted_received_amount
16
+ t.string :bank_code
17
+ t.string :retail_outlet_name
18
+ t.string :ewallet_type
19
+ t.string :on_demand_link
20
+ t.string :recurring_payment_id
21
+ t.bigint :paid_amount
22
+ t.string :mid_label
23
+ t.string :currency
24
+ t.string :success_redirect_url
25
+ t.string :failure_redirect_url
26
+ t.datetime :paid_at
27
+ t.string :credit_card_charge_id
28
+ t.string :payment_method
29
+ t.string :payment_channel
30
+ t.string :payment_destination
31
+
32
+ t.references :invoice
33
+ t.timestamps
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateXenditRecurrings < ActiveRecord::Migration[6.0]
4
+ def change
5
+ create_table :xendit_recurrings, id: :string do |t|
6
+ t.string :user_id
7
+ t.string :external_id
8
+ t.string :status
9
+ t.string :amount
10
+ t.string :payer_email
11
+ t.text :description
12
+ t.boolean :send_email
13
+ t.string :interval
14
+ t.integer :interval_count
15
+ t.integer :total_recurrence
16
+ t.integer :recurrence_progress
17
+ t.string :last_created_invoice_url
18
+ t.string :credit_card_token
19
+ t.string :success_redirect_url
20
+ t.string :failure_redirect_url
21
+ t.integer :invoice_duration
22
+ t.boolean :charge_immediately
23
+ t.boolean :recharge
24
+ t.timestamps
25
+ end
26
+ end
27
+ end
data/lib/xendit-rails.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'xendit/rails/engine'
3
+ require "xendit/rails/engine"
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Xendit::Invoice::PaymentReceiver
4
+ def initialize(xendit_params)
5
+ @xendit_params = xendit_params
6
+ end
7
+
8
+ def perform!
9
+ create_or_update_recurring! if xendit_params[:recurring_payment_id]
10
+ create_or_update_invoice!
11
+ create_xendit_payment!
12
+ end
13
+
14
+ private
15
+
16
+ attr_reader :xendit_params
17
+
18
+ def create_or_update_recurring!
19
+ recurring = Xendit::Recurring
20
+ .find_or_create_by(id: xendit_params[:recurring_payment_id])
21
+ recurring.update!(xendit_params.permit(Xendit::Recurring.allowed_attributes))
22
+ end
23
+
24
+ def create_or_update_invoice!
25
+ invoice = Xendit::Invoice
26
+ .find_or_create_by(id: xendit_params[:id])
27
+ invoice.update!(xendit_params.permit(Xendit::Invoice.allowed_attributes))
28
+ end
29
+
30
+ def create_xendit_payment!
31
+ Xendit::InvoicePayment.create!(xendit_payment_params)
32
+ end
33
+
34
+ def xendit_payment_params
35
+ xendit_params
36
+ .permit(Xendit::InvoicePayment.allowed_attributes)
37
+ .merge(invoice_id: xendit_params[:id])
38
+ end
39
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Xendit
4
+ autoload :TimestampMapable, "xendit/concerns/orderable"
4
5
  module Rails
5
6
  class Engine < ::Rails::Engine
6
7
  isolate_namespace Xendit
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Xendit
4
4
  module Rails
5
- VERSION = '0.0.1'
5
+ VERSION = '0.0.2'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xendit-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yana Agun Siswanto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-10 00:00:00.000000000 Z
11
+ date: 2020-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -55,17 +55,26 @@ files:
55
55
  - README.md
56
56
  - Rakefile
57
57
  - app/controllers/xendit/application_controller.rb
58
+ - app/controllers/xendit/callbacks/invoices_controller.rb
58
59
  - app/controllers/xendit/callbacks/virtual_accounts_controller.rb
59
60
  - app/jobs/xendit/application_job.rb
60
61
  - app/mailers/xendit/application_mailer.rb
62
+ - app/models/concerns/xendit/timestamp_mapable.rb
61
63
  - app/models/xendit/application_record.rb
64
+ - app/models/xendit/invoice.rb
65
+ - app/models/xendit/invoice_payment.rb
62
66
  - app/models/xendit/payment.rb
67
+ - app/models/xendit/recurring.rb
63
68
  - app/models/xendit/virtual_account.rb
64
69
  - config/routes.rb
65
70
  - db/migrate/20200410162121_create_xendit_virtual_accounts.rb
66
71
  - db/migrate/20200410182702_create_xendit_payments.rb
72
+ - db/migrate/20200411130721_create_xendit_invoices.rb
73
+ - db/migrate/20200411154950_create_xendit_invoice_payments.rb
74
+ - db/migrate/20200411160747_create_xendit_recurrings.rb
67
75
  - lib/tasks/xendit/rails_tasks.rake
68
76
  - lib/xendit-rails.rb
77
+ - lib/xendit/invoice/payment_receiver.rb
69
78
  - lib/xendit/rails/engine.rb
70
79
  - lib/xendit/rails/version.rb
71
80
  homepage: http://github.com/bekicot/xendit-rails
@@ -87,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
96
  - !ruby/object:Gem::Version
88
97
  version: '0'
89
98
  requirements: []
90
- rubygems_version: 3.1.2
99
+ rubygems_version: 3.0.3
91
100
  signing_key:
92
101
  specification_version: 4
93
102
  summary: Quickly add payment to your rails app using xendit.