Class: Clt::CreditCard
- Inherits:
-
Object
- Object
- Clt::CreditCard
- Includes:
- GeneralMethods
- Defined in:
- lib/clt/credit_card.rb
Instance Method Summary collapse
-
#auth_fail_callback_valid?(params) ⇒ Boolean
Authorize fail callback validation.
-
#auth_success_callback_valid?(params) ⇒ Boolean
Authorize success callback validation.
-
#initialize ⇒ CreditCard
constructor
A new instance of CreditCard.
-
#order_cancel(params = {}) ⇒ Object
Order Cancel.
-
#order_create(params = {}) ⇒ Object
Order Create.
-
#order_refund(params = {}) ⇒ Object
Order Refund.
Methods included from GeneralMethods
#apn_notice_valid?, #generate_checksum
Constructor Details
#initialize ⇒ CreditCard
Returns a new instance of CreditCard.
5 6 7 8 9 10 11 12 13 |
# File 'lib/clt/credit_card.rb', line 5 def initialize raise ArgumentError, 'Please setup cocs_link_id first' if Clt.cocs_link_id.nil? ErrorMessage.raise_error(msg: :parameter_should_be, field: :cocs_link_id, data: :String) unless Clt.cocs_link_id.is_a? String ErrorMessage.raise_error(msg: :cannot_be_empty, field: :cocs_link_id) if Clt.cocs_link_id.empty? raise ArgumentError, 'Please setup cocs_hash_base first' if Clt.cocs_hash_base.nil? ErrorMessage.raise_error(msg: :parameter_should_be, field: :cocs_hash_base, data: :String) unless Clt.cocs_hash_base.is_a? String ErrorMessage.raise_error(msg: :cannot_be_empty, field: :cocs_hash_base) if Clt.cocs_hash_base.empty? end |
Instance Method Details
#auth_fail_callback_valid?(params) ⇒ Boolean
Authorize fail callback validation
155 156 157 158 159 160 161 |
# File 'lib/clt/credit_card.rb', line 155 def auth_fail_callback_valid?(params) params = params.stringify_keys checksum = params['chk'] checksum_generated = generate_checksum "#{Clt.cocs_hash_base}$#{params['order_amount']}$#{params['send_time']}$#{params['ret']}$#{params['notify_time']}$#{params['cust_order_no']}" checksum == checksum_generated end |
#auth_success_callback_valid?(params) ⇒ Boolean
Authorize success callback validation
146 147 148 149 150 151 152 |
# File 'lib/clt/credit_card.rb', line 146 def auth_success_callback_valid?(params) params = params.stringify_keys checksum = params['chk'] checksum_generated = generate_checksum "#{Clt.cocs_hash_base}$#{params['order_amount']}$#{params['send_time']}$#{params['ret']}$#{params['acquire_time']}$#{params['auth_code']}$#{params['card_no']}$#{params['notify_time']}$#{params['cust_order_no']}" checksum == checksum_generated end |
#order_cancel(params = {}) ⇒ Object
Order Cancel
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/clt/credit_card.rb', line 68 def order_cancel(params = {}) ErrorMessage.raise_error(msg: :parameter_should_be, field: :Parameter, data: :Hash) unless params.is_a? Hash ErrorMessage.raise_error(msg: :missing_parameter, field: :service_url) if params[:service_url].nil? ErrorMessage.raise_error(msg: :parameter_should_be, field: :service_url, data: :String) unless params[:service_url].is_a? String ErrorMessage.raise_error(msg: :cannot_be_empty, field: :service_url) if params[:service_url].empty? ErrorMessage.raise_error(msg: :parameter_should_be, field: :cust_order_no, data: :String) unless params[:cust_order_no].is_a? String ErrorMessage.raise_error(msg: :cannot_be_empty, field: :cust_order_no) if params[:cust_order_no].empty? ErrorMessage.raise_error(msg: :missing_parameter, field: :order_amount) if params[:order_amount].nil? ErrorMessage.raise_error(msg: :parameter_should_be, field: :order_amount, data: :Integer) unless params[:order_amount].is_a? Integer ErrorMessage.raise_error(msg: :parameter_should_be, field: :order_amount, data: 'greater than 0') if params[:order_amount] <= 0 if params.has_key? :chk raise_error(msg: :parameter_should_be, field: :chk, data: :String) unless params[:chk].is_a? String raise_error(msg: :cannot_be_empty, field: :chk) if params[:chk].empty? end # get and converts time to local time current_time = Time.now.localtime('+08:00') data = { link_id: Clt.cocs_link_id, send_time: current_time.strftime('%F %T') }.merge(params).merge(return_type: 'json') unless params.has_key? :chk data[:chk] = generate_checksum "#{Clt.cocs_hash_base}$#{params[:cust_order_no]}$#{params[:order_amount]}$#{data[:send_time]}" end post_request(service_url: params[:service_url], data: data) end |
#order_create(params = {}) ⇒ Object
Order Create
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/clt/credit_card.rb', line 16 def order_create(params = {}) ErrorMessage.raise_error(msg: :parameter_should_be, field: :Parameter, data: :Hash) unless params.is_a? Hash ErrorMessage.raise_error(msg: :missing_parameter, field: :service_url) if params[:service_url].nil? ErrorMessage.raise_error(msg: :parameter_should_be, field: :service_url, data: :String) unless params[:service_url].is_a? String ErrorMessage.raise_error(msg: :cannot_be_empty, field: :service_url) if params[:service_url].empty? if params.has_key? :cust_order_no ErrorMessage.raise_error(msg: :parameter_should_be, field: :cust_order_no, data: :String) unless params[:cust_order_no].is_a? String ErrorMessage.raise_error(msg: :cannot_be_empty, field: :cust_order_no) if params[:cust_order_no].empty? ErrorMessage.raise_error(msg: :data_length_too_short, field: :cust_order_no) if params[:cust_order_no].size < 3 end ErrorMessage.raise_error(msg: :missing_parameter, field: :order_amount) if params[:order_amount].nil? ErrorMessage.raise_error(msg: :parameter_should_be, field: :order_amount, data: :Integer) unless params[:order_amount].is_a? Integer ErrorMessage.raise_error(msg: :parameter_should_be, field: :order_amount, data: 'greater than 0') if params[:order_amount] <= 0 ErrorMessage.raise_error(msg: :missing_parameter, field: :order_detail) if params[:order_detail].nil? ErrorMessage.raise_error(msg: :parameter_should_be, field: :order_detail, data: :String) unless params[:order_detail].is_a? String ErrorMessage.raise_error(msg: :cannot_be_empty, field: :order_detail) if params[:order_detail].empty? if params.has_key? :limit_product_id ErrorMessage.raise_error(msg: :parameter_should_be, field: :limit_product_id, data: :String) unless params[:limit_product_id].is_a? String ErrorMessage.raise_error(msg: :cannot_be_empty, field: :limit_product_id) if params[:limit_product_id].empty? end if params.has_key? :chk raise_error(msg: :parameter_should_be, field: :chk, data: :String) unless params[:chk].is_a? String raise_error(msg: :cannot_be_empty, field: :chk) if params[:chk].empty? end service_url = params[:service_url] params.delete :service_url # get and converts time to local time current_time = Time.now.localtime('+08:00') data = { link_id: Clt.cocs_link_id, cust_order_no: '', limit_product_id: 'esun.normal', send_time: current_time.strftime('%F %T') }.merge(params).merge(return_type: 'json') unless params.has_key? :chk data[:chk] = generate_checksum "#{Clt.cocs_hash_base}$#{params[:order_amount]}$#{data[:send_time]}" end post_request(service_url: service_url, data: data) end |
#order_refund(params = {}) ⇒ Object
Order Refund
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/clt/credit_card.rb', line 103 def order_refund(params = {}) ErrorMessage.raise_error(msg: :parameter_should_be, field: :Parameter, data: :Hash) unless params.is_a? Hash ErrorMessage.raise_error(msg: :missing_parameter, field: :service_url) if params[:service_url].nil? ErrorMessage.raise_error(msg: :parameter_should_be, field: :service_url, data: :String) unless params[:service_url].is_a? String ErrorMessage.raise_error(msg: :cannot_be_empty, field: :service_url) if params[:service_url].empty? ErrorMessage.raise_error(msg: :parameter_should_be, field: :cust_order_no, data: :String) unless params[:cust_order_no].is_a? String ErrorMessage.raise_error(msg: :cannot_be_empty, field: :cust_order_no) if params[:cust_order_no].empty? ErrorMessage.raise_error(msg: :missing_parameter, field: :order_amount) if params[:order_amount].nil? ErrorMessage.raise_error(msg: :parameter_should_be, field: :order_amount, data: :Integer) unless params[:order_amount].is_a? Integer ErrorMessage.raise_error(msg: :parameter_should_be, field: :order_amount, data: 'greater than 0') if params[:order_amount] <= 0 ErrorMessage.raise_error(msg: :missing_parameter, field: :refund_amount) if params[:refund_amount].nil? ErrorMessage.raise_error(msg: :parameter_should_be, field: :refund_amount, data: :Integer) unless params[:refund_amount].is_a? Integer ErrorMessage.raise_error(msg: :parameter_should_be, field: :refund_amount, data: 'greater than 0') if params[:refund_amount] <= 0 if params[:refund_amount] > params[:order_amount] ErrorMessage.raise_error(msg: :parameter_should_be, field: :refund_amount, data: 'less than or equal to order_amount') end if params.has_key? :chk raise_error(msg: :parameter_should_be, field: :chk, data: :String) unless params[:chk].is_a? String raise_error(msg: :cannot_be_empty, field: :chk) if params[:chk].empty? end # get and converts time to local time current_time = Time.now.localtime('+08:00') data = { link_id: Clt.cocs_link_id, send_time: current_time.strftime('%F %T') }.merge(params).merge(return_type: 'json') unless params.has_key? :chk data[:chk] = generate_checksum "#{Clt.cocs_hash_base}$#{params[:cust_order_no]}$#{params[:order_amount]}$#{params[:refund_amount]}$#{data[:send_time]}" end post_request(service_url: params[:service_url], data: data) end |