Class: Sinopac::FunBiz::Gateway
- Inherits:
-
Object
- Object
- Sinopac::FunBiz::Gateway
- Defined in:
- lib/sinopac/funbiz/gateway.rb
Instance Attribute Summary collapse
-
#shop_no ⇒ Object
readonly
Returns the value of attribute shop_no.
Instance Method Summary collapse
- #build_atm_order(order:, **options) ⇒ Object
- #build_creditcard_order(order:, **options) ⇒ Object
- #get_nonce ⇒ Object
- #hash_id ⇒ Object
-
#initialize(shop_no: nil, hashes: nil, end_point: nil, return_url: nil, backend_url: nil) ⇒ Gateway
constructor
A new instance of Gateway.
- #order_create_request_params(order_params:) ⇒ Object
- #order_pay_query_request_params(data:) ⇒ Object
- #order_query_request_params(data:) ⇒ Object
- #pay!(pay_type:, order:, **options) ⇒ Object
- #query_order(shop_no: nil, order_no:) ⇒ Object
- #query_pay_order(shop_no: nil, pay_token:) ⇒ Object
Constructor Details
#initialize(shop_no: nil, hashes: nil, end_point: nil, return_url: nil, backend_url: nil) ⇒ Gateway
Returns a new instance of Gateway.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/sinopac/funbiz/gateway.rb', line 10 def initialize(shop_no: nil, hashes: nil, end_point: nil, return_url: nil, backend_url: nil) @shop_no = shop_no || ENV['FUNBIZ_SHOP_NO'] @hashes = hashes || { a1: ENV['FUNBIZ_HASH_A1'], a2: ENV['FUNBIZ_HASH_A2'], b1: ENV['FUNBIZ_HASH_B1'], b2: ENV['FUNBIZ_HASH_B2'] } @end_point = end_point || ENV['FUNBIZ_END_POINT'] @return_url = return_url || ENV['FUNBIZ_RETURN_URL'] @backend_url = backend_url || ENV['FUNBIZ_BACKEND_URL'] end |
Instance Attribute Details
#shop_no ⇒ Object (readonly)
Returns the value of attribute shop_no.
8 9 10 |
# File 'lib/sinopac/funbiz/gateway.rb', line 8 def shop_no @shop_no end |
Instance Method Details
#build_atm_order(order:, **options) ⇒ Object
31 32 33 |
# File 'lib/sinopac/funbiz/gateway.rb', line 31 def build_atm_order(order:, **) build_order(order: order, type: :atm, **) end |
#build_creditcard_order(order:, **options) ⇒ Object
35 36 37 |
# File 'lib/sinopac/funbiz/gateway.rb', line 35 def build_creditcard_order(order:, **) build_order(order: order, type: :credit_card, **) end |
#get_nonce ⇒ Object
23 24 25 |
# File 'lib/sinopac/funbiz/gateway.rb', line 23 def get_nonce @nonce ||= Nonce.get_nonce(shop_no: @shop_no, end_point: @end_point) end |
#hash_id ⇒ Object
27 28 29 |
# File 'lib/sinopac/funbiz/gateway.rb', line 27 def hash_id Hash.hash_id(@hashes) end |
#order_create_request_params(order_params:) ⇒ Object
39 40 41 |
# File 'lib/sinopac/funbiz/gateway.rb', line 39 def order_create_request_params(order_params:) build_request_params(order_params: order_params, service_type: 'OrderCreate') end |
#order_pay_query_request_params(data:) ⇒ Object
43 44 45 |
# File 'lib/sinopac/funbiz/gateway.rb', line 43 def order_pay_query_request_params(data:) build_request_params(order_params: data, service_type: 'OrderPayQuery') end |
#order_query_request_params(data:) ⇒ Object
47 48 49 |
# File 'lib/sinopac/funbiz/gateway.rb', line 47 def order_query_request_params(data:) build_request_params(order_params: data, service_type: 'OrderQuery') end |
#pay!(pay_type:, order:, **options) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/sinopac/funbiz/gateway.rb', line 51 def pay!(pay_type:, order:, **) order_params = case pay_type when :credit_card build_creditcard_order(order: order, **) when :atm build_atm_order(order: order, **) else raise "payment method is not supported yet!" end request_params = order_create_request_params(order_params: order_params) url = URI("#{@end_point}/Order") header = { "Content-Type" => "application/json" } resp = Net::HTTP.post(url, request_params.to_json, header) result = (content: JSON.parse(resp.body)) Result.new(result) end |
#query_order(shop_no: nil, order_no:) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/sinopac/funbiz/gateway.rb', line 71 def query_order(shop_no: nil, order_no:) data = { ShopNo: shop_no || @shop_no, OrderNo: order_no } request_params = order_query_request_params(data: data) url = URI("#{@end_point}/Order") header = { "Content-Type" => "application/json" } resp = Net::HTTP.post(url, request_params.to_json, header) result = (content: JSON.parse(resp.body)) OrderResult.new(result) end |
#query_pay_order(shop_no: nil, pay_token:) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/sinopac/funbiz/gateway.rb', line 87 def query_pay_order(shop_no: nil, pay_token:) data = { ShopNo: shop_no || @shop_no, PayToken: pay_token } request_params = order_pay_query_request_params(data: data) url = URI("#{@end_point}/Order") header = { "Content-Type" => "application/json" } resp = Net::HTTP.post(url, request_params.to_json, header) result = (content: JSON.parse(resp.body)) TransactionResult.new(result) end |