instamojo-ruby 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +83 -0
- data/LICENSE.txt +20 -0
- data/README.md +287 -0
- data/README.rdoc +89 -0
- data/Rakefile +44 -0
- data/VERSION +1 -0
- data/instamojo-ruby.gemspec +79 -0
- data/lib/API/api.rb +47 -0
- data/lib/Instamojo-rb.rb +15 -0
- data/lib/base.rb +8 -0
- data/lib/client/client.rb +227 -0
- data/lib/client/link.rb +60 -0
- data/lib/client/payment.rb +60 -0
- data/lib/client/payment_request.rb +44 -0
- data/lib/client/refund.rb +35 -0
- data/lib/common_object.rb +54 -0
- data/lib/response.rb +26 -0
- data/lib/utility.rb +15 -0
- data/spec/Instamojo-rb_spec.rb +7 -0
- data/spec/spec_helper.rb +12 -0
- metadata +155 -0
@@ -0,0 +1,60 @@
|
|
1
|
+
module Instamojo
|
2
|
+
|
3
|
+
=begin Example
|
4
|
+
{
|
5
|
+
"payment_id" => "MOJO3815000F72853519",
|
6
|
+
"quantity" => 1,
|
7
|
+
"status" => "Credit",
|
8
|
+
"link_slug" => "demo-product",
|
9
|
+
"link_title" => "Demo product",
|
10
|
+
"buyer_name" => "",
|
11
|
+
"buyer_phone" => "",
|
12
|
+
"buyer_email" => "nalinc007@gmail.com",
|
13
|
+
"currency" => "Free",
|
14
|
+
"unit_price" => "0.00",
|
15
|
+
"amount" => "0.00",
|
16
|
+
"fees" => "0",
|
17
|
+
"shipping_address" => nil,
|
18
|
+
"shipping_city" => nil,
|
19
|
+
"shipping_state" => nil,
|
20
|
+
"shipping_zip" => nil,
|
21
|
+
"shipping_country" => nil,
|
22
|
+
"discount_code" => nil,
|
23
|
+
"discount_amount_off" => nil,
|
24
|
+
"variants" => [],
|
25
|
+
"custom_fields" => {},
|
26
|
+
"affiliate_id" => nil,
|
27
|
+
"affiliate_commission" => nil,
|
28
|
+
"created_at" => "2013-08-15T13:16:24.629Z"
|
29
|
+
}
|
30
|
+
=end
|
31
|
+
|
32
|
+
class Payment
|
33
|
+
attr_accessor :payment_id, :quantity, :status, :link_slug, :link_title, :buyer_name, :buyer_phone, :buyer_email
|
34
|
+
attr_accessor :currency, :unit_price, :amount, :fees, :shipping_address, :shipping_city, :shipping_state, :shipping_zip
|
35
|
+
attr_accessor :shipping_country, :discount_code, :discount_amount_off, :variants, :custom_fields, :affiliate_id, :affiliate_commission, :created_at
|
36
|
+
|
37
|
+
attr_reader :original
|
38
|
+
include CommonObject
|
39
|
+
detail_method :payment_detail, :payment_id
|
40
|
+
|
41
|
+
def initialize(payment, client)
|
42
|
+
assign_values(payment)
|
43
|
+
@client = client # Reference to client
|
44
|
+
end
|
45
|
+
|
46
|
+
# Process refund for this payment
|
47
|
+
# payment.process_refund(type: 'QFL', body: 'Customer is not satisfied')
|
48
|
+
def process_refund(hash = {}, &block)
|
49
|
+
hash[:payment_id] = self.payment_id
|
50
|
+
@client.create_refund(hash, &block)
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_s
|
54
|
+
sprintf("Instamojo Payment(payment_id: %s, quantity: %s, amount: %s, status: %s, link_slug: %s, buyer_name: %s)",
|
55
|
+
payment_id, quantity, amount, status, link_slug, buyer_name)
|
56
|
+
end
|
57
|
+
|
58
|
+
alias_method :create_refund, :process_refund
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Instamojo
|
2
|
+
|
3
|
+
=begin Example
|
4
|
+
{
|
5
|
+
"id" => "92e58bd771414d05a5e443b0a85f8b43",
|
6
|
+
"phone" => "+919999999999",
|
7
|
+
"email" => "foo@example.com",
|
8
|
+
"buyer_name" => "John Doe",
|
9
|
+
"amount" => "2500",
|
10
|
+
"purpose" => "FIFA 16",
|
11
|
+
"status" => "Pending",
|
12
|
+
"send_sms" => true,
|
13
|
+
"send_email" => true,
|
14
|
+
"sms_status" => "Pending",
|
15
|
+
"email_status" => "Pending",
|
16
|
+
"shorturl" => nil,
|
17
|
+
"longurl" => "https://www.instamojo.com/@ashwini/92e58bd771414d05a5e443b0a85f8b43",
|
18
|
+
"redirect_url" => "http://www.example.com/redirect/",
|
19
|
+
"webhook" => "http://www.example.com/webhook/",
|
20
|
+
"created_at" => "2015-10-07T21:36:34.665Z",
|
21
|
+
"modified_at" => "2015-10-07T21:36:34.665Z",
|
22
|
+
"allow_repeated_payments" => false
|
23
|
+
}
|
24
|
+
=end
|
25
|
+
|
26
|
+
class PaymentRequest
|
27
|
+
attr_accessor :id, :phone, :email, :buyer_name, :amount, :purpose, :status, :send_sms, :send_email, :sms_status
|
28
|
+
attr_accessor :email_status, :shorturl, :longurl, :redirect_url, :webhook, :created_at, :modified_at, :allow_repeated_payments
|
29
|
+
|
30
|
+
attr_reader :original
|
31
|
+
include CommonObject
|
32
|
+
detail_method :payment_request_status, :id
|
33
|
+
|
34
|
+
def initialize(payment_request, client)
|
35
|
+
assign_values(payment_request)
|
36
|
+
@client = client # Reference to client
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_s
|
40
|
+
sprintf("Instamojo PaymentRequest(id: %s, purpose: %s, amount: %s, status: %s, shorturl: %s, longurl: %s)",
|
41
|
+
id, purpose, amount, status, shorturl, longurl)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Instamojo
|
2
|
+
|
3
|
+
=begin example
|
4
|
+
{
|
5
|
+
"refund_amount" => "100",
|
6
|
+
"payment_id" => "MOJO5c04000J30502939",
|
7
|
+
"body" => "Customer isn't satisfied with the quality",
|
8
|
+
"status" => "Refunded",
|
9
|
+
"created_at" => "2015-12-07T11:01:37.640Z",
|
10
|
+
"id" => "C5c0751269",
|
11
|
+
"total_amount" => "100.00",
|
12
|
+
"type" => "QFL"
|
13
|
+
}
|
14
|
+
=end
|
15
|
+
|
16
|
+
class Refund
|
17
|
+
attr_accessor :id, :payment_id, :status, :type, :body, :refund_amount, :total_amount, :created_at
|
18
|
+
|
19
|
+
attr_reader :original
|
20
|
+
|
21
|
+
include CommonObject
|
22
|
+
detail_method :refund_detail, :payment_id
|
23
|
+
|
24
|
+
def initialize(refund, client)
|
25
|
+
assign_values(refund)
|
26
|
+
@client = client
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_s
|
30
|
+
sprintf("Instamojo Refund(id: %s, status: %s, payment_id: %s, refund_amount: %s)",
|
31
|
+
id, status, payment_id, refund_amount)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Instamojo
|
2
|
+
module CommonObject
|
3
|
+
|
4
|
+
# Common intializer
|
5
|
+
def assign_values(object)
|
6
|
+
@original = object
|
7
|
+
object.each do |k, v|
|
8
|
+
instance_variable_set("@#{k}", v)
|
9
|
+
end
|
10
|
+
self
|
11
|
+
end
|
12
|
+
|
13
|
+
# Return link/payment/payment_request/refund as json
|
14
|
+
def to_json
|
15
|
+
construct_hash.to_json
|
16
|
+
end
|
17
|
+
|
18
|
+
# Return link/payment/payment_request/refund as hash
|
19
|
+
def to_h
|
20
|
+
construct_hash
|
21
|
+
end
|
22
|
+
|
23
|
+
# Reload the link/payment/payment_request/refund from the server
|
24
|
+
def reload
|
25
|
+
@client.send(*self.detail_helper)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Same as relaod but mutable
|
29
|
+
def reload!
|
30
|
+
obj = reload
|
31
|
+
obj.instance_of?(self.class) ? assign_values(obj.to_h) : obj
|
32
|
+
end
|
33
|
+
|
34
|
+
# Construct hash from mutated parameters
|
35
|
+
def construct_hash
|
36
|
+
vars = instance_variables.reject { |x| [:@client, :@original].include? x }
|
37
|
+
Hash[vars.map { |key| [key.to_s[1..key.length], instance_variable_get(key)] }]
|
38
|
+
end
|
39
|
+
|
40
|
+
alias_method :refresh, :reload
|
41
|
+
alias_method :refresh!, :reload!
|
42
|
+
def self.included(klass)
|
43
|
+
klass.extend(KlassMethods)
|
44
|
+
end
|
45
|
+
|
46
|
+
module KlassMethods
|
47
|
+
def detail_method(detail, key)
|
48
|
+
define_method "detail_helper" do
|
49
|
+
[detail, self.send("#{key}")]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/response.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Instamojo
|
2
|
+
class Response
|
3
|
+
attr_reader :body, :code
|
4
|
+
|
5
|
+
def initialize(hash)
|
6
|
+
@code = hash.status
|
7
|
+
if hash.body
|
8
|
+
begin
|
9
|
+
@body = JSON.parse(hash.body)
|
10
|
+
rescue JSON::ParserError
|
11
|
+
@body = {:client_error => "Something went wrong", :original => hash.body.to_s}
|
12
|
+
end
|
13
|
+
@body.symbolize_keys!
|
14
|
+
@status = @body[:success]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def response_success?
|
19
|
+
[200, 201, 202, 203, 204].include? @code
|
20
|
+
end
|
21
|
+
|
22
|
+
def success?
|
23
|
+
(@status && (@status.eql?(true) || @status.downcase == 'success')) || response_success?
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/utility.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'Instamojo-rb'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: instamojo-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Instamojo Technologies
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.8.8
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.8.8
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rest-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.8'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.8'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: jeweler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.8'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.8'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: debugger
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.6'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.6'
|
97
|
+
description: Instamojo Ruby library - Assists you to programmatically create, edit
|
98
|
+
and delete offers on Instamojo. Also supports listing, updation and details of Payments,
|
99
|
+
Payments Requests and Refunds.
|
100
|
+
email: dev-accounts@instamojo.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files:
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.md
|
106
|
+
- README.rdoc
|
107
|
+
files:
|
108
|
+
- ".document"
|
109
|
+
- ".rspec"
|
110
|
+
- Gemfile
|
111
|
+
- Gemfile.lock
|
112
|
+
- LICENSE.txt
|
113
|
+
- README.md
|
114
|
+
- README.rdoc
|
115
|
+
- Rakefile
|
116
|
+
- VERSION
|
117
|
+
- instamojo-ruby.gemspec
|
118
|
+
- lib/API/api.rb
|
119
|
+
- lib/Instamojo-rb.rb
|
120
|
+
- lib/base.rb
|
121
|
+
- lib/client/client.rb
|
122
|
+
- lib/client/link.rb
|
123
|
+
- lib/client/payment.rb
|
124
|
+
- lib/client/payment_request.rb
|
125
|
+
- lib/client/refund.rb
|
126
|
+
- lib/common_object.rb
|
127
|
+
- lib/response.rb
|
128
|
+
- lib/utility.rb
|
129
|
+
- spec/Instamojo-rb_spec.rb
|
130
|
+
- spec/spec_helper.rb
|
131
|
+
homepage: http://github.com/Instamojo/Instamojo-rb
|
132
|
+
licenses:
|
133
|
+
- MIT
|
134
|
+
metadata: {}
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
requirements: []
|
150
|
+
rubygems_version: 3.0.4
|
151
|
+
signing_key:
|
152
|
+
specification_version: 4
|
153
|
+
summary: Instamojo Ruby library - Assists you to programmatically create, edit and
|
154
|
+
delete offers on Instamojo
|
155
|
+
test_files: []
|