xendit-rails 0.0.1
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/README.md +42 -0
- data/Rakefile +34 -0
- data/app/controllers/xendit/application_controller.rb +7 -0
- data/app/controllers/xendit/callbacks/virtual_accounts_controller.rb +38 -0
- data/app/jobs/xendit/application_job.rb +6 -0
- data/app/mailers/xendit/application_mailer.rb +8 -0
- data/app/models/xendit/application_record.rb +7 -0
- data/app/models/xendit/payment.rb +14 -0
- data/app/models/xendit/virtual_account.rb +28 -0
- data/config/routes.rb +10 -0
- data/db/migrate/20200410162121_create_xendit_virtual_accounts.rb +24 -0
- data/db/migrate/20200410182702_create_xendit_payments.rb +14 -0
- data/lib/tasks/xendit/rails_tasks.rake +4 -0
- data/lib/xendit-rails.rb +3 -0
- data/lib/xendit/rails/engine.rb +10 -0
- data/lib/xendit/rails/version.rb +7 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3899b263ecde063c35214087df81bf125063d294e5de2e8bb62b30a42d47b933
|
4
|
+
data.tar.gz: d60cff9bce184189f73fb0e927cb997a22335cdbaa6fc9e59bd9e6e38ea657da
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1a43512dd1d48ab766a8fe0c4477f0c8829fa48346e7ba7b7a83db7126232e07cecbfd85089ea1c16d789f4b01fd37284422230eb9f8bdc14fd9a3cf933323e5
|
7
|
+
data.tar.gz: d680f424894ff36d7ac291e19830c26aefa72f2fba3fe90de1dfa079640a83e318b3a3484d24830e88754edbcdb9db5ffd445849bb55f0c28755fe0e2bc6a1f0
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2020 Yana Agun Siswanto
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# Xendit Rails
|
2
|
+
A drop in rails engine for receiving payment via xendit.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
Add the gem to your Gemfile
|
6
|
+
```
|
7
|
+
gem 'xendit-rails', github: 'bekicot/xendit-rails'
|
8
|
+
```
|
9
|
+
|
10
|
+
And then execute:
|
11
|
+
```bash
|
12
|
+
$ bundle
|
13
|
+
```
|
14
|
+
|
15
|
+
Copy migration files
|
16
|
+
```bash
|
17
|
+
$ bin/rails xendit:install:migrations
|
18
|
+
```
|
19
|
+
|
20
|
+
Mount the engine to your routes
|
21
|
+
```rb
|
22
|
+
mount Xendit::Rails::Engine => 'xendit-rails'
|
23
|
+
```
|
24
|
+
|
25
|
+
And then add the callback to your xendit account
|
26
|
+
```
|
27
|
+
FVA Paid:
|
28
|
+
https://yourdomain.com/xendit-rails/callbacks/virtual_accounts/paid
|
29
|
+
|
30
|
+
FVA Created:
|
31
|
+
https://yourdomain.com/xendit-rails/callbacks/virtual_accounts/
|
32
|
+
```
|
33
|
+
|
34
|
+
## Support
|
35
|
+
[Github Issue](https://github.com/issues)
|
36
|
+
[Email Me](mailto:yana.developer@gmail.com)
|
37
|
+
|
38
|
+
Nuhun!!
|
39
|
+
|
40
|
+
|
41
|
+
## License
|
42
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
begin
|
4
|
+
require "bundler/setup"
|
5
|
+
rescue LoadError
|
6
|
+
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
|
7
|
+
end
|
8
|
+
|
9
|
+
require "rdoc/task"
|
10
|
+
|
11
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
12
|
+
rdoc.rdoc_dir = "rdoc"
|
13
|
+
rdoc.title = "Xendit::Rails"
|
14
|
+
rdoc.options << "--line-numbers"
|
15
|
+
rdoc.rdoc_files.include("README.md")
|
16
|
+
rdoc.rdoc_files.include("lib/**/*.rb")
|
17
|
+
end
|
18
|
+
|
19
|
+
APP_RAKEFILE = File.expand_path("test/dummy_app/Rakefile", __dir__)
|
20
|
+
load "rails/tasks/engine.rake"
|
21
|
+
|
22
|
+
load "rails/tasks/statistics.rake"
|
23
|
+
|
24
|
+
require "bundler/gem_tasks"
|
25
|
+
|
26
|
+
require "rake/testtask"
|
27
|
+
|
28
|
+
Rake::TestTask.new(:test) do |t|
|
29
|
+
t.libs << "test"
|
30
|
+
t.pattern = "test/**/*_test.rb"
|
31
|
+
t.verbose = false
|
32
|
+
end
|
33
|
+
|
34
|
+
task default: :test
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_dependency 'xendit/application_controller'
|
4
|
+
|
5
|
+
module Xendit::Callbacks
|
6
|
+
class VirtualAccountsController < Xendit::ApplicationController
|
7
|
+
def update
|
8
|
+
xendit_va = Xendit::VirtualAccount.find_or_create_by id: params[:id]
|
9
|
+
xendit_va.update!(virtual_account_params)
|
10
|
+
head :ok
|
11
|
+
end
|
12
|
+
|
13
|
+
def paid
|
14
|
+
xendit_va = Xendit::VirtualAccount
|
15
|
+
.find_or_initialize_by(
|
16
|
+
id: params[:callback_virtual_account_id]
|
17
|
+
)
|
18
|
+
if xendit_va.new_record?
|
19
|
+
xendit_va.assign_attributes(virtual_account_params)
|
20
|
+
xendit_va.save!
|
21
|
+
end
|
22
|
+
Xendit::Payment
|
23
|
+
.create!(payment_params.merge(virtual_account: xendit_va))
|
24
|
+
head :ok
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def payment_params
|
30
|
+
@payment_params ||= params.permit(Xendit::Payment::ATTRIBUTES)
|
31
|
+
end
|
32
|
+
|
33
|
+
def virtual_account_params
|
34
|
+
@virtual_account_params = params
|
35
|
+
.permit(Xendit::VirtualAccount::ATTRIBUTES)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Xendit
|
4
|
+
class Payment < ApplicationRecord
|
5
|
+
alias_attribute :callback_virtual_account_id, :virtual_account_id
|
6
|
+
alias_attribute :payment_id, :id
|
7
|
+
|
8
|
+
ATTRIBUTES = %i[amount transaction_timestamp
|
9
|
+
payment_id
|
10
|
+
callback_virtual_account_id].freeze
|
11
|
+
|
12
|
+
belongs_to :virtual_account
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Xendit
|
4
|
+
class VirtualAccount < ApplicationRecord
|
5
|
+
alias_attribute :is_closed, :closed
|
6
|
+
alias_attribute :is_single_use, :single_use
|
7
|
+
alias_attribute :virtual_account_number, :account_number
|
8
|
+
|
9
|
+
ATTRIBUTES = [:id,
|
10
|
+
:is_closed,
|
11
|
+
:is_single_use,
|
12
|
+
:virtual_account_number,
|
13
|
+
:owner_id,
|
14
|
+
:external_id,
|
15
|
+
:bank_code,
|
16
|
+
:merchant_code,
|
17
|
+
:name,
|
18
|
+
:account_number,
|
19
|
+
:expiration_date,
|
20
|
+
:closed,
|
21
|
+
:single_use,
|
22
|
+
:status,
|
23
|
+
# Comming from response when creating a new virtual_account
|
24
|
+
:expected_amount,
|
25
|
+
:description,
|
26
|
+
:currency].freeze
|
27
|
+
end
|
28
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class CreateXenditVirtualAccounts < ActiveRecord::Migration[6.0]
|
4
|
+
def change
|
5
|
+
create_table :xendit_virtual_accounts, id: :string do |t|
|
6
|
+
t.string :owner_id
|
7
|
+
t.string :external_id
|
8
|
+
t.string :bank_code
|
9
|
+
t.string :merchant_code
|
10
|
+
t.string :name
|
11
|
+
t.string :account_number
|
12
|
+
t.datetime :expiration_date
|
13
|
+
t.boolean :closed
|
14
|
+
t.boolean :single_use
|
15
|
+
t.string :status
|
16
|
+
|
17
|
+
# Comming from response when creating a new virtual_account
|
18
|
+
t.bigint :expected_amount
|
19
|
+
t.text :description
|
20
|
+
t.string :currency
|
21
|
+
t.timestamps
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class CreateXenditPayments < ActiveRecord::Migration[6.0]
|
4
|
+
def change
|
5
|
+
create_table :xendit_payments, id: :string do |t|
|
6
|
+
t.bigint :amount
|
7
|
+
t.datetime :transaction_timestamp
|
8
|
+
t.references :virtual_account,
|
9
|
+
foreign_key: { to_table: :xendit_virtual_accounts },
|
10
|
+
type: :string
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/xendit-rails.rb
ADDED
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xendit-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yana Agun Siswanto
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-04-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 6.0.2
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 6.0.2.2
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 6.0.2
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 6.0.2.2
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: sqlite3
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
description: Quickly add payment to your rails app using xendit.
|
48
|
+
email:
|
49
|
+
- yana.developer@gmail.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- MIT-LICENSE
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- app/controllers/xendit/application_controller.rb
|
58
|
+
- app/controllers/xendit/callbacks/virtual_accounts_controller.rb
|
59
|
+
- app/jobs/xendit/application_job.rb
|
60
|
+
- app/mailers/xendit/application_mailer.rb
|
61
|
+
- app/models/xendit/application_record.rb
|
62
|
+
- app/models/xendit/payment.rb
|
63
|
+
- app/models/xendit/virtual_account.rb
|
64
|
+
- config/routes.rb
|
65
|
+
- db/migrate/20200410162121_create_xendit_virtual_accounts.rb
|
66
|
+
- db/migrate/20200410182702_create_xendit_payments.rb
|
67
|
+
- lib/tasks/xendit/rails_tasks.rake
|
68
|
+
- lib/xendit-rails.rb
|
69
|
+
- lib/xendit/rails/engine.rb
|
70
|
+
- lib/xendit/rails/version.rb
|
71
|
+
homepage: http://github.com/bekicot/xendit-rails
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubygems_version: 3.1.2
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Quickly add payment to your rails app using xendit.
|
94
|
+
test_files: []
|