Class: Clt::Cvs

Inherits:
Object
  • Object
show all
Includes:
GeneralMethods
Defined in:
lib/clt/cvs.rb

Instance Method Summary collapse

Methods included from GeneralMethods

#apn_notice_valid?, #generate_checksum

Constructor Details

#initializeCvs

Returns a new instance of Cvs.

Raises:

  • (ArgumentError)


5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/clt/cvs.rb', line 5

def initialize
  raise ArgumentError, 'Please setup cvs_cust_id first' if Clt.cvs_cust_id.nil?
  ErrorMessage.raise_error(msg: :parameter_should_be, field: :cvs_cust_id, data: :String) unless Clt.cvs_cust_id.is_a? String
  ErrorMessage.raise_error(msg: :cannot_be_empty, field: :cvs_cust_id) if Clt.cvs_cust_id.empty?

  raise ArgumentError, 'Please setup cvs_cust_password first' if Clt.cvs_cust_password.nil?
  ErrorMessage.raise_error(msg: :parameter_should_be, field: :cvs_cust_password, data: :String) unless Clt.cvs_cust_password.is_a? String
  ErrorMessage.raise_error(msg: :cannot_be_empty, field: :cvs_cust_password) if Clt.cvs_cust_password.empty?

  ErrorMessage.raise_error(msg: :parameter_should_be, field: :cvs_default_expire_day, data: :Integer) unless Clt.cvs_default_expire_day.is_a? Integer
  ErrorMessage.raise_error(msg: :parameter_should_be, field: :cvs_default_expire_day, data: 'greater than 0') if Clt.cvs_default_expire_day <= 0
end

Instance Method Details

#order_create(params = {}) ⇒ Object



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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/clt/cvs.rb', line 18

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?

  ErrorMessage.raise_error(msg: :missing_parameter, field: :cust_order_number) if params[:cust_order_number].nil?
  ErrorMessage.raise_error(msg: :parameter_should_be, field: :cust_order_number, data: :String) unless params[:cust_order_number].is_a? String
  ErrorMessage.raise_error(msg: :cannot_be_empty, field: :cust_order_number) if params[:cust_order_number].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

  if params.has_key? :expire_date
    ErrorMessage.raise_error(msg: :parameter_should_be, field: :expire_date, data: :String) unless params[:expire_date].is_a? String
    ErrorMessage.raise_error(msg: :cannot_be_empty, field: :expire_date) if params[:expire_date].empty?
    ErrorMessage.raise_error(msg: :wrong_data_format, field: :expire_date) unless /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+\d{2}:\d{2}\z/.match(params[:expire_date])
  end

  if params.has_key? :payer_name
    ErrorMessage.raise_error(msg: :parameter_should_be, field: :payer_name, data: :String) unless params[:payer_name].is_a? String
  end

  if params.has_key? :payer_postcode
    ErrorMessage.raise_error(msg: :parameter_should_be, field: :payer_postcode, data: :String) unless params[:payer_postcode].is_a? String
  end

  if params.has_key? :payer_address
    ErrorMessage.raise_error(msg: :parameter_should_be, field: :payer_address, data: :String) unless params[:payer_address].is_a? String
  end

  ErrorMessage.raise_error(msg: :missing_parameter, field: :payer_mobile) if params[:payer_mobile].nil?
  ErrorMessage.raise_error(msg: :parameter_should_be, field: :payer_mobile, data: :String) unless params[:payer_mobile].is_a? String
  ErrorMessage.raise_error(msg: :cannot_be_empty, field: :payer_mobile) if params[:payer_mobile].empty?

  ErrorMessage.raise_error(msg: :missing_parameter, field: :payer_email) if params[:payer_email].nil?
  ErrorMessage.raise_error(msg: :parameter_should_be, field: :payer_email, data: :String) unless params[:payer_email].is_a? String
  ErrorMessage.raise_error(msg: :cannot_be_empty, field: :payer_email) if params[:payer_email].empty?

  expire_date = params.has_key?(:expire_date) ? params[:expire_date] : get_cvs_default_expire_date

  # build xml data
  builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do
    request {
      header {
        cmd 'cvs_order_regiater'
        cust_id Clt.cvs_cust_id
        cust_password Clt.cvs_cust_password
      }
      order {
        cust_order_number params[:cust_order_number]
        order_amount params[:order_amount]
        expire_date expire_date
        payer_name params[:payer_name]
        payer_postcode params[:payer_postcode]
        payer_address params[:payer_address]
        payer_mobile params[:payer_mobile]
        payer_email params[:payer_email]
      }
    }
  end

  post_request(service_url: params[:service_url], data: builder.to_xml)
end

#order_query(params = {}) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/clt/cvs.rb', line 84

def order_query(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: :missing_parameter, field: :process_code_update_time_begin) if params[:process_code_update_time_begin].nil?
  ErrorMessage.raise_error(msg: :parameter_should_be, field: :process_code_update_time_begin, data: :String) unless params[:process_code_update_time_begin].is_a? String
  ErrorMessage.raise_error(msg: :cannot_be_empty, field: :process_code_update_time_begin) if params[:process_code_update_time_begin].empty?
  ErrorMessage.raise_error(msg: :wrong_data_format, field: :process_code_update_time_begin) unless /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+\d{2}:\d{2}\z/.match(params[:process_code_update_time_begin])

  ErrorMessage.raise_error(msg: :missing_parameter, field: :process_code_update_time_end) if params[:process_code_update_time_end].nil?
  ErrorMessage.raise_error(msg: :parameter_should_be, field: :process_code_update_time_end, data: :String) unless params[:process_code_update_time_end].is_a? String
  ErrorMessage.raise_error(msg: :cannot_be_empty, field: :process_code_update_time_end) if params[:process_code_update_time_end].empty?
  ErrorMessage.raise_error(msg: :wrong_data_format, field: :process_code_update_time_end) unless /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+\d{2}:\d{2}\z/.match(params[:process_code_update_time_end])

  builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do
    request {
      header {
        cmd 'cvs_order_query'
        cust_id Clt.cvs_cust_id
        cust_password Clt.cvs_cust_password
      }
      query {
        process_code_update_time_begin params[:process_code_update_time_begin]
        process_code_update_time_end params[:process_code_update_time_end]
      }
    }
  end

  post_request(service_url: params[:service_url], data: builder.to_xml)
end