paymaya 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.rubocop.yml +75 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +9 -0
- data/LICENSE.md +7 -0
- data/README.md +35 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/fixtures/vcr_cassettes/create_card.yml +54 -0
- data/fixtures/vcr_cassettes/create_card_vault_payment.yml +55 -0
- data/fixtures/vcr_cassettes/create_checkout.yml +65 -0
- data/fixtures/vcr_cassettes/create_customer.yml +58 -0
- data/fixtures/vcr_cassettes/create_payment.yml +57 -0
- data/fixtures/vcr_cassettes/create_payment_token.yml +54 -0
- data/fixtures/vcr_cassettes/create_subscription.yml +54 -0
- data/fixtures/vcr_cassettes/delete_card.yml +50 -0
- data/fixtures/vcr_cassettes/delete_checkout_webhook.yml +107 -0
- data/fixtures/vcr_cassettes/delete_customer.yml +52 -0
- data/fixtures/vcr_cassettes/delete_payment_vault_webhook.yml +50 -0
- data/fixtures/vcr_cassettes/delete_subscription.yml +50 -0
- data/fixtures/vcr_cassettes/get_customization.yml +57 -0
- data/fixtures/vcr_cassettes/list_cards.yml +50 -0
- data/fixtures/vcr_cassettes/list_checkout_webhooks.yml +54 -0
- data/fixtures/vcr_cassettes/list_payment_vault_webhooks.yml +50 -0
- data/fixtures/vcr_cassettes/list_refunds.yml +51 -0
- data/fixtures/vcr_cassettes/list_subscription_payments.yml +52 -0
- data/fixtures/vcr_cassettes/list_subscriptions.yml +50 -0
- data/fixtures/vcr_cassettes/refund_payment.yml +54 -0
- data/fixtures/vcr_cassettes/register_checkout_webhook.yml +60 -0
- data/fixtures/vcr_cassettes/register_payment_vault_webhook.yml +54 -0
- data/fixtures/vcr_cassettes/remove_customization.yml +56 -0
- data/fixtures/vcr_cassettes/retrieve_card.yml +50 -0
- data/fixtures/vcr_cassettes/retrieve_checkout.yml +61 -0
- data/fixtures/vcr_cassettes/retrieve_customer.yml +52 -0
- data/fixtures/vcr_cassettes/retrieve_payment.yml +51 -0
- data/fixtures/vcr_cassettes/retrieve_payment_vault_webhook.yml +50 -0
- data/fixtures/vcr_cassettes/retrieve_refund.yml +51 -0
- data/fixtures/vcr_cassettes/retrieve_subscription.yml +50 -0
- data/fixtures/vcr_cassettes/set_customization.yml +62 -0
- data/fixtures/vcr_cassettes/update_card.yml +52 -0
- data/fixtures/vcr_cassettes/update_checkout_webhook.yml +113 -0
- data/fixtures/vcr_cassettes/update_customer.yml +56 -0
- data/fixtures/vcr_cassettes/update_payment_vault_webhook.yml +52 -0
- data/fixtures/vcr_cassettes/void_payment.yml +53 -0
- data/lib/paymaya.rb +28 -0
- data/lib/paymaya/checkout.rb +5 -0
- data/lib/paymaya/checkout/checkout.rb +35 -0
- data/lib/paymaya/checkout/customization.rb +37 -0
- data/lib/paymaya/checkout/webhook.rb +40 -0
- data/lib/paymaya/configuration.rb +22 -0
- data/lib/paymaya/helper.rb +114 -0
- data/lib/paymaya/payment_vault/card_vault/card.rb +44 -0
- data/lib/paymaya/payment_vault/card_vault/customer.rb +38 -0
- data/lib/paymaya/payment_vault/card_vault/payment.rb +24 -0
- data/lib/paymaya/payment_vault/card_vault/subscription.rb +50 -0
- data/lib/paymaya/payment_vault/payment.rb +58 -0
- data/lib/paymaya/payment_vault/payment_token.rb +20 -0
- data/lib/paymaya/payment_vault/webhook.rb +44 -0
- data/lib/paymaya/version.rb +4 -0
- data/paymaya.gemspec +29 -0
- metadata +205 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'rest-client'
|
3
|
+
|
4
|
+
require 'paymaya/helper'
|
5
|
+
|
6
|
+
module Paymaya
|
7
|
+
module Checkout
|
8
|
+
module Customization
|
9
|
+
def self.set(logo_url:, icon_url:, apple_touch_icon_url:, custom_title:,
|
10
|
+
color_scheme:)
|
11
|
+
Helper.request(:post, customization_url, {
|
12
|
+
logo_url: logo_url,
|
13
|
+
icon_url: icon_url,
|
14
|
+
apple_touch_icon_url: apple_touch_icon_url,
|
15
|
+
custom_title: custom_title,
|
16
|
+
color_scheme: color_scheme
|
17
|
+
}, Helper.checkout_secret_auth_headers)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.get
|
21
|
+
Helper.request(:get, customization_url, {},
|
22
|
+
Helper.checkout_secret_auth_headers)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.remove
|
26
|
+
Helper.request(:delete, customization_url, {},
|
27
|
+
Helper.checkout_secret_auth_headers)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.customization_url
|
31
|
+
"#{Paymaya.config.base_url}/checkout/v1/customizations"
|
32
|
+
end
|
33
|
+
|
34
|
+
private_class_method :customization_url
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'rest-client'
|
3
|
+
|
4
|
+
require 'paymaya/helper'
|
5
|
+
|
6
|
+
module Paymaya
|
7
|
+
module Checkout
|
8
|
+
module Webhook
|
9
|
+
def self.register(name:, callback_url:)
|
10
|
+
Helper.request(:post, webhook_url, {
|
11
|
+
name: name,
|
12
|
+
callback_url: callback_url
|
13
|
+
}, Helper.checkout_secret_auth_headers)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.list
|
17
|
+
Helper.request(:get, webhook_url, {},
|
18
|
+
Helper.checkout_secret_auth_headers)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.delete(id)
|
22
|
+
Helper.request(:delete, "#{webhook_url}/#{id}", {},
|
23
|
+
Helper.checkout_secret_auth_headers)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.update(id, name:, callback_url:)
|
27
|
+
Helper.request(:put, "#{webhook_url}/#{id}", {
|
28
|
+
name: name,
|
29
|
+
callback_url: callback_url
|
30
|
+
}, Helper.checkout_secret_auth_headers)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.webhook_url
|
34
|
+
"#{Paymaya.config.base_url}/checkout/v1/webhooks"
|
35
|
+
end
|
36
|
+
|
37
|
+
private_class_method :webhook_url
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Paymaya
|
3
|
+
class Configuration
|
4
|
+
attr_accessor :payment_vault_public_key, :payment_vault_secret_key,
|
5
|
+
:checkout_public_key, :checkout_secret_key
|
6
|
+
attr_writer :base_url, :mode
|
7
|
+
|
8
|
+
SANDBOX_BASE_URL = 'https://pg-sandbox.paymaya.com'.freeze
|
9
|
+
PROD_BASE_URL = 'https://pg.paymaya.com'.freeze
|
10
|
+
|
11
|
+
def base_url
|
12
|
+
return @base_url unless @base_url.nil?
|
13
|
+
return SANDBOX_BASE_URL if mode == :sandbox
|
14
|
+
PROD_BASE_URL
|
15
|
+
end
|
16
|
+
|
17
|
+
def mode
|
18
|
+
return @mode unless @mode.nil?
|
19
|
+
:sandbox
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'awrence'
|
3
|
+
require 'plissken'
|
4
|
+
|
5
|
+
require 'money'
|
6
|
+
|
7
|
+
module Paymaya
|
8
|
+
module Helper
|
9
|
+
def self.payment_facilitator(submerchant_id:, submerchant_name:,
|
10
|
+
submerchant_city:, submerchant_pos_country:, submerchant_country_code:,
|
11
|
+
submerchant_state_code: nil)
|
12
|
+
pf = {
|
13
|
+
smi: submerchant_id,
|
14
|
+
smn: submerchant_name,
|
15
|
+
mci: submerchant_city,
|
16
|
+
mpc: submerchant_pos_country,
|
17
|
+
mco: submerchant_country_code
|
18
|
+
}
|
19
|
+
pf[:mst] = submerchant_state_code unless submerchant_state_code.nil?
|
20
|
+
pf
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.snakify(input)
|
24
|
+
transform(input, :snakify, :to_snake_keys)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.camelify(input)
|
28
|
+
transform(input, :camelify, :to_camelback_keys)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.transform(input, method_name, hash_method)
|
32
|
+
return transform_array(input, method_name) if input.is_a? Array
|
33
|
+
return transform_hash(input, method_name, hash_method) if input.is_a? Hash
|
34
|
+
input
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.transform_array(input, method_name)
|
38
|
+
input.map do |elem|
|
39
|
+
send(method_name, elem)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.transform_hash(input, method_name, hash_method)
|
44
|
+
hash = input.send(hash_method)
|
45
|
+
hash.each do |k, v|
|
46
|
+
hash[k] = send(method_name, v) if v.is_a? Array
|
47
|
+
end
|
48
|
+
hash
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.stringify_numbers(input, currency)
|
52
|
+
if input.is_a? Hash
|
53
|
+
output = {}
|
54
|
+
input.each do |k, v|
|
55
|
+
output[k] = if (MONEY_PARAMS.include? k) && (v.is_a? Numeric)
|
56
|
+
format_amount(v, currency)
|
57
|
+
else
|
58
|
+
stringify_numbers(v, currency)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
output
|
62
|
+
elsif input.is_a? Array
|
63
|
+
input.map do |elem|
|
64
|
+
stringify_numbers(elem, currency)
|
65
|
+
end
|
66
|
+
else
|
67
|
+
input.to_s
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.payment_vault_public_auth_headers
|
72
|
+
auth_headers(Paymaya.config.payment_vault_public_key)
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.payment_vault_secret_auth_headers
|
76
|
+
auth_headers(Paymaya.config.payment_vault_secret_key)
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.checkout_public_auth_headers
|
80
|
+
auth_headers(Paymaya.config.checkout_public_key)
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.checkout_secret_auth_headers
|
84
|
+
auth_headers(Paymaya.config.checkout_secret_key)
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.auth_headers(key)
|
88
|
+
{
|
89
|
+
authorization:
|
90
|
+
"Basic #{Base64.strict_encode64(key + ':').chomp}",
|
91
|
+
content_type: 'application/json'
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.request(method, url, params, headers)
|
96
|
+
response = RestClient::Request.execute(
|
97
|
+
method: method, url: url,
|
98
|
+
headers: headers, payload: camelify(params).to_json
|
99
|
+
)
|
100
|
+
snakify(JSON.parse(response))
|
101
|
+
end
|
102
|
+
|
103
|
+
MONEY_PARAMS = [
|
104
|
+
:tax, :subtotal, :discount, :shipping_fee, :amount, :value
|
105
|
+
].freeze
|
106
|
+
|
107
|
+
def self.format_amount(num, currency)
|
108
|
+
Money.new(num, currency, '').to_s
|
109
|
+
end
|
110
|
+
|
111
|
+
private_class_method :transform, :transform_array, :transform_hash,
|
112
|
+
:auth_headers
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'rest-client'
|
3
|
+
|
4
|
+
require 'paymaya/helper'
|
5
|
+
|
6
|
+
module Paymaya
|
7
|
+
module PaymentVault
|
8
|
+
module CardVault
|
9
|
+
module Card
|
10
|
+
def self.create(customer_id, card)
|
11
|
+
Helper.request(:post, card_url(customer_id),
|
12
|
+
card, Helper.payment_vault_secret_auth_headers)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.list(customer_id)
|
16
|
+
Helper.request(:get, card_url(customer_id), {},
|
17
|
+
Helper.payment_vault_secret_auth_headers)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.retrieve(customer_id, id)
|
21
|
+
Helper.request(:get, "#{card_url(customer_id)}/#{id}", {},
|
22
|
+
Helper.payment_vault_secret_auth_headers)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.delete(customer_id, id)
|
26
|
+
Helper.request(:delete, "#{card_url(customer_id)}/#{id}", {},
|
27
|
+
Helper.payment_vault_secret_auth_headers)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.update(customer_id, id, card)
|
31
|
+
Helper.request(:put, "#{card_url(customer_id)}/#{id}",
|
32
|
+
card, Helper.payment_vault_secret_auth_headers)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.card_url(customer_id)
|
36
|
+
"#{Paymaya.config.base_url}/payments/v1/customers/#{customer_id}/" \
|
37
|
+
'cards'
|
38
|
+
end
|
39
|
+
|
40
|
+
private_class_method :card_url
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'rest-client'
|
3
|
+
|
4
|
+
require 'paymaya/helper'
|
5
|
+
|
6
|
+
module Paymaya
|
7
|
+
module PaymentVault
|
8
|
+
module CardVault
|
9
|
+
module Customer
|
10
|
+
def self.create(customer)
|
11
|
+
Helper.request(:post, customer_url,
|
12
|
+
customer, Helper.payment_vault_secret_auth_headers)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.retrieve(id)
|
16
|
+
Helper.request(:get, "#{customer_url}/#{id}", {},
|
17
|
+
Helper.payment_vault_secret_auth_headers)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.delete(id)
|
21
|
+
Helper.request(:delete, "#{customer_url}/#{id}", {},
|
22
|
+
Helper.payment_vault_secret_auth_headers)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.update(id, customer)
|
26
|
+
Helper.request(:put, "#{customer_url}/#{id}",
|
27
|
+
customer, Helper.payment_vault_secret_auth_headers)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.customer_url
|
31
|
+
"#{Paymaya.config.base_url}/payments/v1/customers"
|
32
|
+
end
|
33
|
+
|
34
|
+
private_class_method :customer_url
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'rest-client'
|
3
|
+
|
4
|
+
require 'paymaya/helper'
|
5
|
+
|
6
|
+
module Paymaya
|
7
|
+
module PaymentVault
|
8
|
+
module CardVault
|
9
|
+
module Payment
|
10
|
+
def self.create(customer_id, card_token, payment)
|
11
|
+
Helper.request(:post, payment_url(customer_id, card_token),
|
12
|
+
payment, Helper.payment_vault_secret_auth_headers)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.payment_url(customer_id, card_token)
|
16
|
+
"#{Paymaya.config.base_url}/payments/v1/customers/#{customer_id}/" \
|
17
|
+
"cards/#{card_token}/payments"
|
18
|
+
end
|
19
|
+
|
20
|
+
private_class_method :payment_url
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'rest-client'
|
3
|
+
|
4
|
+
require 'paymaya/helper'
|
5
|
+
|
6
|
+
module Paymaya
|
7
|
+
module PaymentVault
|
8
|
+
module CardVault
|
9
|
+
module Subscription
|
10
|
+
def self.create(customer_id, card_token, payment)
|
11
|
+
Helper.request(:post,
|
12
|
+
customer_subscription_url(customer_id, card_token),
|
13
|
+
payment, Helper.payment_vault_secret_auth_headers)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.list(customer_id, card_token)
|
17
|
+
Helper.request(:get,
|
18
|
+
customer_subscription_url(customer_id, card_token),
|
19
|
+
{}, Helper.payment_vault_secret_auth_headers)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.retrieve(id)
|
23
|
+
Helper.request(:get, subscription_url(id), {},
|
24
|
+
Helper.payment_vault_secret_auth_headers)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.delete(id)
|
28
|
+
Helper.request(:delete, subscription_url(id), {},
|
29
|
+
Helper.payment_vault_secret_auth_headers)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.list_payments(id)
|
33
|
+
Helper.request(:get, "#{subscription_url(id)}/payments", {},
|
34
|
+
Helper.payment_vault_secret_auth_headers)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.customer_subscription_url(customer_id, card_token)
|
38
|
+
"#{Paymaya.config.base_url}/payments/v1/customers/#{customer_id}/" \
|
39
|
+
"cards/#{card_token}/subscriptions"
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.subscription_url(id)
|
43
|
+
"#{Paymaya.config.base_url}/payments/v1/subscriptions/#{id}"
|
44
|
+
end
|
45
|
+
|
46
|
+
private_class_method :subscription_url
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'rest-client'
|
3
|
+
|
4
|
+
require 'paymaya/helper'
|
5
|
+
|
6
|
+
module Paymaya
|
7
|
+
module PaymentVault
|
8
|
+
module Payment
|
9
|
+
def self.create(payment_token_id:, total_amount:, buyer:,
|
10
|
+
metadata: nil)
|
11
|
+
payload = {
|
12
|
+
total_amount: total_amount,
|
13
|
+
buyer: buyer,
|
14
|
+
payment_token_id: payment_token_id
|
15
|
+
}
|
16
|
+
payload[:metadata] = metadata unless metadata.nil?
|
17
|
+
Helper.request(:post, payment_url, payload,
|
18
|
+
Helper.payment_vault_secret_auth_headers)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.retrieve(id)
|
22
|
+
Helper.request(:get, "#{payment_url}/#{id}", {},
|
23
|
+
Helper.payment_vault_secret_auth_headers)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.void(id, reason)
|
27
|
+
Helper.request(:delete, "#{payment_url}/#{id}", {
|
28
|
+
reason: reason
|
29
|
+
}, Helper.payment_vault_secret_auth_headers)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.refund(id, total_amount, reason)
|
33
|
+
payload = {
|
34
|
+
total_amount: total_amount,
|
35
|
+
reason: reason
|
36
|
+
}
|
37
|
+
Helper.request(:post, "#{payment_url}/#{id}/refunds",
|
38
|
+
payload, Helper.payment_vault_secret_auth_headers)
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.list_refunds(id)
|
42
|
+
Helper.request(:get, "#{payment_url}/#{id}/refunds",
|
43
|
+
{}, Helper.payment_vault_secret_auth_headers)
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.retrieve_refund(payment, id)
|
47
|
+
Helper.request(:get, "#{payment_url}/#{payment}/refunds/#{id}",
|
48
|
+
{}, Helper.payment_vault_secret_auth_headers)
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.payment_url
|
52
|
+
"#{Paymaya.config.base_url}/payments/v1/payments"
|
53
|
+
end
|
54
|
+
|
55
|
+
private_class_method :payment_url
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'rest-client'
|
3
|
+
require 'paymaya/helper'
|
4
|
+
|
5
|
+
module Paymaya
|
6
|
+
module PaymentVault
|
7
|
+
module PaymentToken
|
8
|
+
def self.create(card)
|
9
|
+
Helper.request(:post, payment_token_url, card,
|
10
|
+
Helper.payment_vault_public_auth_headers)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.payment_token_url
|
14
|
+
"#{Paymaya.config.base_url}/payments/v1/payment-tokens"
|
15
|
+
end
|
16
|
+
|
17
|
+
private_class_method :payment_token_url
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|