mpower 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/nukturnal/mpower_ruby)
2
+
1
3
  # MpowerRuby
2
4
 
3
5
  MPower Payments Ruby Client Library
@@ -0,0 +1,89 @@
1
+ module MPower
2
+ module Onsite
3
+ class Invoice < MPower::Checkout::Invoice
4
+
5
+ attr_accessor :invoice_token
6
+
7
+ def initialize
8
+ super
9
+ end
10
+
11
+ def charge(opr_token,confirm_token)
12
+ payload = {
13
+ :token => opr_token,
14
+ :confirm_token => confirm_token
15
+ }
16
+
17
+ result = http_json_request(MPower::Setup.opr_charge_base_url,payload)
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"]
29
+ @response_code = result["response_code"]
30
+ @response_text = result["response_text"]
31
+ true
32
+ else
33
+ @response_code = result["response_code"]
34
+ @response_text = result["response_text"]
35
+ false
36
+ end
37
+ end
38
+
39
+ 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
+
62
+ payload = {
63
+ :invoice_data => invoice_data,
64
+ :opr_data => {
65
+ :account_alias => account_alias
66
+ }
67
+ }
68
+
69
+ 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
85
+ end
86
+
87
+ end
88
+ end
89
+ end
@@ -61,26 +61,26 @@ module MPower
61
61
  end
62
62
 
63
63
  def confirm(token)
64
- result = http_get_request("#{MPower::Setup.checkout_confirm_base_url}#{token}");
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']
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
76
  true
77
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']
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
84
  @response_text = "Invoice status is #{result['status'].upcase}"
85
85
  false
86
86
  end
@@ -8,7 +8,8 @@ module MPower
8
8
  end
9
9
  end
10
10
 
11
- %w(checkout/invoice
11
+ %w(checkout/redirect_invoice
12
+ checkout/onsite_invoice
12
13
  checkout/store
13
14
  ).each do |lib|
14
15
  require File.join(File.dirname(__FILE__), lib)
data/lib/mpower/setup.rb CHANGED
@@ -6,10 +6,15 @@ module MPower
6
6
  @@token = nil
7
7
  @@mode = "test"
8
8
 
9
- LIVE_CHECKOUT_INVOICE_BASE_URL = "https://app.mpowerpayments.com/api/v1/checkout-invoice/create"
10
- TEST_CHECKOUT_INVOICE_BASE_URL = "https://app.mpowerpayments.com/sandbox-api/v1/checkout-invoice/create"
11
- LIVE_CHECKOUT_CONFIRM_BASE_URL = "https://app.mpowerpayments.com/api/v1/checkout-invoice/confirm/"
12
- TEST_CHECKOUT_CONFIRM_BASE_URL = "https://app.mpowerpayments.com/sandbox-api/v1/checkout-invoice/confirm/"
9
+ ROOT_URL_BASE = "http://localhost:3000"
10
+ LIVE_CHECKOUT_INVOICE_BASE_URL = "#{ROOT_URL_BASE}/api/v1/checkout-invoice/create"
11
+ TEST_CHECKOUT_INVOICE_BASE_URL = "#{ROOT_URL_BASE}/sandbox-api/v1/checkout-invoice/create"
12
+ LIVE_CHECKOUT_CONFIRM_BASE_URL = "#{ROOT_URL_BASE}/api/v1/checkout-invoice/confirm/"
13
+ TEST_CHECKOUT_CONFIRM_BASE_URL = "#{ROOT_URL_BASE}/sandbox-api/v1/checkout-invoice/confirm/"
14
+ LIVE_OPR_BASE_URL = "#{ROOT_URL_BASE}/api/v1/opr/create"
15
+ TEST_OPR_BASE_URL = "#{ROOT_URL_BASE}/sandbox-api/v1/opr/create"
16
+ LIVE_OPR_CHARGE_BASE_URL = "#{ROOT_URL_BASE}/api/v1/opr/charge"
17
+ TEST_OPR_CHARGE_BASE_URL = "#{ROOT_URL_BASE}/sandbox-api/v1/opr/charge"
13
18
 
14
19
  def self.master_key=(master_key); @@master_key = master_key; end
15
20
  def self.master_key; @@master_key; end
@@ -30,5 +35,14 @@ module MPower
30
35
  def self.checkout_confirm_base_url
31
36
  @@mode == "live" ? LIVE_CHECKOUT_CONFIRM_BASE_URL : TEST_CHECKOUT_CONFIRM_BASE_URL
32
37
  end
38
+
39
+ def self.opr_base_url
40
+ @@mode == "live" ? LIVE_OPR_BASE_URL : TEST_OPR_BASE_URL
41
+ end
42
+
43
+ def self.opr_charge_base_url
44
+ @@mode == "live" ? LIVE_OPR_CHARGE_BASE_URL : TEST_OPR_CHARGE_BASE_URL
45
+ end
46
+
33
47
  end
34
48
  end
@@ -1,3 +1,3 @@
1
1
  module MPower
2
- VERSION = "1.0.7"
2
+ VERSION = "1.0.8"
3
3
  end
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.7
4
+ version: 1.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-09 00:00:00.000000000 Z
12
+ date: 2012-11-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -89,7 +89,8 @@ files:
89
89
  - Rakefile
90
90
  - lib/mpower.rb
91
91
  - lib/mpower/checkout.rb
92
- - lib/mpower/checkout/invoice.rb
92
+ - lib/mpower/checkout/onsite_invoice.rb
93
+ - lib/mpower/checkout/redirect_invoice.rb
93
94
  - lib/mpower/checkout/store.rb
94
95
  - lib/mpower/setup.rb
95
96
  - lib/mpower/utilities.rb