mpower 1.0.8 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,16 +16,8 @@ module MPower
16
16
 
17
17
  result = http_json_request(MPower::Setup.opr_charge_base_url,payload)
18
18
 
19
- case result["response_code"]
20
- when "00"
21
- @status = result["invoice_data"]["status"]
22
- @customer = result["invoice_data"]["customer"]
23
- @items = result["invoice_data"]["invoice"]["items"]
24
- @taxes = result["invoice_data"]["invoice"]["taxes"]
25
- @description = result["invoice_data"]["invoice"]["description"]
26
- @custom_data = result["invoice_data"]["custom_data"]
27
- @total_amount = result["invoice_data"]["invoice"]["total_amount"]
28
- @receipt_url = result["invoice_data"]["receipt_url"]
19
+ if result["response_code"] == "00"
20
+ rebuild_invoice(result["invoice_data"])
29
21
  @response_code = result["response_code"]
30
22
  @response_text = result["response_text"]
31
23
  true
@@ -37,51 +29,16 @@ module MPower
37
29
  end
38
30
 
39
31
  def create(account_alias)
40
- invoice_data = {
41
- :invoice => {
42
- :items => @items,
43
- :taxes => @taxes,
44
- :total_amount => @total_amount,
45
- :description => description
46
- },
47
- :store => {
48
- :name => @store.name,
49
- :tagline => @store.tagline,
50
- :postal_address => @store.postal_address,
51
- :phone => @store.phone_number,
52
- :logo_url => @store.logo_url,
53
- :website_url => @store.website_url
54
- },
55
- :custom_data => @custom_data,
56
- :actions => {
57
- :cancel_url => @cancel_url,
58
- :return_url => @return_url
59
- }
60
- }
61
32
 
62
33
  payload = {
63
- :invoice_data => invoice_data,
34
+ :invoice_data => build_invoice_payload,
64
35
  :opr_data => {
65
36
  :account_alias => account_alias
66
37
  }
67
38
  }
68
39
 
69
40
  result = http_json_request(MPower::Setup.opr_base_url,payload)
70
- case result["response_code"]
71
- when "00"
72
- @token = result["token"]
73
- @response_text = result["response_text"]
74
- @response_code = result["response_code"]
75
- @invoice_token = result["invoice_token"]
76
- @status = MPower::SUCCESS
77
- true
78
- else
79
- @response_text = result["response_text"]
80
- @response_code = result["response_code"]
81
- @invoice_url = nil
82
- @status = MPower::FAIL
83
- false
84
- end
41
+ create_response(result)
85
42
  end
86
43
 
87
44
  end
@@ -63,61 +63,70 @@ module MPower
63
63
  def confirm(token)
64
64
  result = http_get_request("#{MPower::Setup.checkout_confirm_base_url}#{token}")
65
65
  if result.size > 0
66
- case result["status"]
67
- when "completed"
68
- @status = result["status"]
69
- @customer = result["customer"]
70
- @items = result["invoice"]["items"]
71
- @taxes = result["invoice"]["taxes"]
72
- @description = result["invoice"]["description"]
73
- @custom_data = result["custom_data"]
74
- @total_amount = result["invoice"]["total_amount"]
75
- @receipt_url = result["receipt_url"]
76
- true
77
- else
78
- @status = result["status"]
79
- @items = result["invoice"]["items"]
80
- @taxes = result["invoice"]["taxes"]
81
- @description = result["invoice"]["description"]
82
- @custom_data = result["custom_data"]
83
- @total_amount = result["invoice"]["total_amount"]
84
- @response_text = "Invoice status is #{result['status'].upcase}"
85
- false
86
- end
87
- else
88
66
  @response_text = "Invoice Not Found"
89
67
  @response_code = 1002
90
68
  @status = MPower::FAIL
69
+ return false
70
+ end
71
+
72
+ if result["status"] == "completed"
73
+ rebuild_invoice(result)
74
+ @response_text = result["response_text"]
75
+ true
76
+ else
77
+ @status = result["status"]
78
+ @items = result["invoice"]["items"]
79
+ @taxes = result["invoice"]["taxes"]
80
+ @description = result["invoice"]["description"]
81
+ @custom_data = result["custom_data"]
82
+ @total_amount = result["invoice"]["total_amount"]
83
+ @response_text = "Invoice status is #{result['status'].upcase}"
91
84
  false
92
85
  end
93
86
  end
94
87
 
95
88
  def create
96
- checkout_payload = {
97
- :invoice => {
98
- :items => @items,
99
- :taxes => @taxes,
100
- :total_amount => @total_amount,
101
- :description => description
102
- },
103
- :store => {
104
- :name => @store.name,
105
- :tagline => @store.tagline,
106
- :postal_address => @store.postal_address,
107
- :phone => @store.phone_number,
108
- :logo_url => @store.logo_url,
109
- :website_url => @store.website_url
110
- },
111
- :custom_data => @custom_data,
112
- :actions => {
113
- :cancel_url => @cancel_url,
114
- :return_url => @return_url
115
- }
89
+ result = http_json_request(MPower::Setup.checkout_base_url,build_invoice_payload)
90
+ create_response(result)
91
+ end
92
+
93
+ protected
94
+ def build_invoice_payload
95
+ { :invoice => {
96
+ :items => @items,
97
+ :taxes => @taxes,
98
+ :total_amount => @total_amount,
99
+ :description => description
100
+ },
101
+ :store => {
102
+ :name => @store.name,
103
+ :tagline => @store.tagline,
104
+ :postal_address => @store.postal_address,
105
+ :phone => @store.phone_number,
106
+ :logo_url => @store.logo_url,
107
+ :website_url => @store.website_url
108
+ },
109
+ :custom_data => @custom_data,
110
+ :actions => {
111
+ :cancel_url => @cancel_url,
112
+ :return_url => @return_url
116
113
  }
114
+ }
115
+ end
117
116
 
118
- result = http_json_request(MPower::Setup.checkout_base_url,checkout_payload)
119
- case result["response_code"]
120
- when "00"
117
+ def rebuild_invoice(result={})
118
+ @status = result["status"]
119
+ @customer = result["customer"]
120
+ @items = result["invoice"]["items"]
121
+ @taxes = result["invoice"]["taxes"]
122
+ @description = result["invoice"]["description"]
123
+ @custom_data = result["custom_data"]
124
+ @total_amount = result["invoice"]["total_amount"]
125
+ @receipt_url = result["receipt_url"]
126
+ end
127
+
128
+ def create_response(result={})
129
+ if result["response_code"] == "00"
121
130
  @token = result["token"]
122
131
  @response_text = result["response_description"]
123
132
  @response_code = result["response_code"]
@@ -132,7 +141,6 @@ module MPower
132
141
  false
133
142
  end
134
143
  end
135
-
136
144
  end
137
145
  end
138
146
  end
data/lib/mpower/setup.rb CHANGED
@@ -6,7 +6,7 @@ module MPower
6
6
  @@token = nil
7
7
  @@mode = "test"
8
8
 
9
- ROOT_URL_BASE = "http://localhost:3000"
9
+ ROOT_URL_BASE = "https://app.mpowerpayments.com"
10
10
  LIVE_CHECKOUT_INVOICE_BASE_URL = "#{ROOT_URL_BASE}/api/v1/checkout-invoice/create"
11
11
  TEST_CHECKOUT_INVOICE_BASE_URL = "#{ROOT_URL_BASE}/sandbox-api/v1/checkout-invoice/create"
12
12
  LIVE_CHECKOUT_CONFIRM_BASE_URL = "#{ROOT_URL_BASE}/api/v1/checkout-invoice/confirm/"
@@ -1,3 +1,3 @@
1
1
  module MPower
2
- VERSION = "1.0.8"
2
+ VERSION = "1.0.9"
3
3
  end
data/mpower.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
10
10
  gem.email = ["alfred@ncodedevlabs.com"]
11
11
  gem.description = %q{Ruby library for integrating with the MPower Gateway}
12
12
  gem.summary = %q{Ruby client bindings for the MPower API}
13
- gem.homepage = "https://github.com/nukturnal/mpower_ruby"
13
+ gem.homepage = "http://mpowerpayments.com/developers/docs/ruby.html"
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mpower
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -96,7 +96,7 @@ files:
96
96
  - lib/mpower/utilities.rb
97
97
  - lib/mpower/version.rb
98
98
  - mpower.gemspec
99
- homepage: https://github.com/nukturnal/mpower_ruby
99
+ homepage: http://mpowerpayments.com/developers/docs/ruby.html
100
100
  licenses: []
101
101
  post_install_message:
102
102
  rdoc_options: []