Instamojo-rb 0.1.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/Gemfile +4 -5
- data/Gemfile.lock +15 -4
- data/Instamojo-rb.gemspec +26 -21
- data/README.md +221 -62
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/API/api.rb +33 -11
- data/lib/Instamojo-rb.rb +9 -6
- data/lib/base.rb +8 -0
- data/lib/client/client.rb +123 -65
- 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
- metadata +27 -52
checksums.yaml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
!binary "U0hBMQ==":
|
|
3
|
+
metadata.gz: !binary |-
|
|
4
|
+
MjFlZWVlYTA1OWFlMmVkYTQ3MzMwZDI5NmZmYWU2NGQ4OTFhMzFmYw==
|
|
5
|
+
data.tar.gz: !binary |-
|
|
6
|
+
MTlhNTczZmM3MTliY2Q0OTYxNWI2OWFjYWFmMGYyOGRiNDBiOTc3ZQ==
|
|
7
|
+
SHA512:
|
|
8
|
+
metadata.gz: !binary |-
|
|
9
|
+
MWM1YzUzZTBiMTgyMmNhODljZDM3Y2ZlZTNiMjZjYjVlMjFkYmIxNDE3YTk0
|
|
10
|
+
YTRhZWMwNDViMjllMjYxOGIxNmU0MzE0NDI4NGVjMWY1Y2IyNDUwMTdlZjU5
|
|
11
|
+
OTA5ZGQ2NDVmMjU5ZGRhMmMyMDQxYTkyMjgxMzQ1NzI3ZDM1NTc=
|
|
12
|
+
data.tar.gz: !binary |-
|
|
13
|
+
Njk1ZDFmYWFhZTkyM2Q4NjI3NWRlNjc4MjljZjcyODEzZDM1ZjAyM2U2Y2Ey
|
|
14
|
+
YTQ1OTU2M2Y2ZGYwNmQyYTZjYTU4ZjEyYjU4ZjJkMzNlMTIyNDhkNWQzNjQx
|
|
15
|
+
ZGQ4OTJiNzg4MGU0MzhiYjFlZGQxODgwNDViNTJlMGYzOTVkOTc=
|
data/Gemfile
CHANGED
|
@@ -3,14 +3,13 @@ source "http://rubygems.org"
|
|
|
3
3
|
# Example:
|
|
4
4
|
# gem "activesupport", ">= 2.3.5"
|
|
5
5
|
gem "faraday", "0.8.8"
|
|
6
|
+
gem 'rest-client', '~> 1.8'
|
|
6
7
|
|
|
7
8
|
# Add dependencies to develop your gem here.
|
|
8
9
|
# Include everything needed to run rake, tests, features, etc.
|
|
9
10
|
group :development do
|
|
10
|
-
gem "rspec", "~> 2.8
|
|
11
|
-
gem "rdoc", "~> 3.12"
|
|
11
|
+
gem "rspec", "~> 2.8"
|
|
12
12
|
gem "bundler", "~> 1.0"
|
|
13
|
-
gem "jeweler", "~> 1.8
|
|
14
|
-
gem "
|
|
15
|
-
gem "debugger"
|
|
13
|
+
gem "jeweler", "~> 1.8"
|
|
14
|
+
gem "debugger", "~> 1.6"
|
|
16
15
|
end
|
data/Gemfile.lock
CHANGED
|
@@ -11,6 +11,8 @@ GEM
|
|
|
11
11
|
debugger-linecache (1.2.0)
|
|
12
12
|
debugger-ruby_core_source (1.3.1)
|
|
13
13
|
diff-lcs (1.1.3)
|
|
14
|
+
domain_name (0.5.25)
|
|
15
|
+
unf (>= 0.0.5, < 1.0.0)
|
|
14
16
|
faraday (0.8.8)
|
|
15
17
|
multipart-post (~> 1.2.0)
|
|
16
18
|
git (1.2.6)
|
|
@@ -23,6 +25,8 @@ GEM
|
|
|
23
25
|
oauth2
|
|
24
26
|
hashie (2.0.5)
|
|
25
27
|
highline (1.6.20)
|
|
28
|
+
http-cookie (1.0.2)
|
|
29
|
+
domain_name (~> 0.5)
|
|
26
30
|
httpauth (0.2.0)
|
|
27
31
|
jeweler (1.8.8)
|
|
28
32
|
builder
|
|
@@ -36,9 +40,11 @@ GEM
|
|
|
36
40
|
json (1.8.1)
|
|
37
41
|
jwt (0.1.8)
|
|
38
42
|
multi_json (>= 1.5)
|
|
43
|
+
mime-types (2.99)
|
|
39
44
|
multi_json (1.8.2)
|
|
40
45
|
multi_xml (0.5.5)
|
|
41
46
|
multipart-post (1.2.0)
|
|
47
|
+
netrc (0.11.0)
|
|
42
48
|
nokogiri (1.5.10)
|
|
43
49
|
oauth2 (0.9.2)
|
|
44
50
|
faraday (~> 0.8)
|
|
@@ -51,6 +57,10 @@ GEM
|
|
|
51
57
|
rake (10.1.1)
|
|
52
58
|
rdoc (3.12.2)
|
|
53
59
|
json (~> 1.4)
|
|
60
|
+
rest-client (1.8.0)
|
|
61
|
+
http-cookie (>= 1.0.2, < 2.0)
|
|
62
|
+
mime-types (>= 1.16, < 3.0)
|
|
63
|
+
netrc (~> 0.7)
|
|
54
64
|
rspec (2.8.0)
|
|
55
65
|
rspec-core (~> 2.8.0)
|
|
56
66
|
rspec-expectations (~> 2.8.0)
|
|
@@ -59,14 +69,15 @@ GEM
|
|
|
59
69
|
rspec-expectations (2.8.0)
|
|
60
70
|
diff-lcs (~> 1.1.2)
|
|
61
71
|
rspec-mocks (2.8.0)
|
|
72
|
+
unf (0.2.0.beta2)
|
|
62
73
|
|
|
63
74
|
PLATFORMS
|
|
64
75
|
ruby
|
|
65
76
|
|
|
66
77
|
DEPENDENCIES
|
|
67
78
|
bundler (~> 1.0)
|
|
68
|
-
debugger
|
|
79
|
+
debugger (~> 1.6)
|
|
69
80
|
faraday (= 0.8.8)
|
|
70
|
-
jeweler (~> 1.8
|
|
71
|
-
|
|
72
|
-
rspec (~> 2.8
|
|
81
|
+
jeweler (~> 1.8)
|
|
82
|
+
rest-client (~> 1.8)
|
|
83
|
+
rspec (~> 2.8)
|
data/Instamojo-rb.gemspec
CHANGED
|
@@ -2,15 +2,17 @@
|
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
|
5
|
+
# stub: Instamojo-rb 1.1.0 ruby lib
|
|
5
6
|
|
|
6
7
|
Gem::Specification.new do |s|
|
|
7
8
|
s.name = "Instamojo-rb"
|
|
8
|
-
s.version = "
|
|
9
|
+
s.version = "1.1.0"
|
|
9
10
|
|
|
10
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
12
|
+
s.require_paths = ["lib"]
|
|
11
13
|
s.authors = ["Ankur Goel"]
|
|
12
|
-
s.date = "
|
|
13
|
-
s.description = "Instamojo Ruby library - Assists you to programmatically create, edit and delete offers on Instamojo"
|
|
14
|
+
s.date = "2015-12-18"
|
|
15
|
+
s.description = "Instamojo Ruby library - Assists you to programmatically create, edit and delete offers on Instamojo. Also supports listing, updation and details of Payments, Payments Requests and Refunds."
|
|
14
16
|
s.email = "ankurgel@gmail.com"
|
|
15
17
|
s.extra_rdoc_files = [
|
|
16
18
|
"LICENSE.txt",
|
|
@@ -30,45 +32,48 @@ Gem::Specification.new do |s|
|
|
|
30
32
|
"VERSION",
|
|
31
33
|
"lib/API/api.rb",
|
|
32
34
|
"lib/Instamojo-rb.rb",
|
|
35
|
+
"lib/base.rb",
|
|
33
36
|
"lib/client/client.rb",
|
|
37
|
+
"lib/client/link.rb",
|
|
38
|
+
"lib/client/payment.rb",
|
|
39
|
+
"lib/client/payment_request.rb",
|
|
40
|
+
"lib/client/refund.rb",
|
|
41
|
+
"lib/common_object.rb",
|
|
42
|
+
"lib/response.rb",
|
|
34
43
|
"lib/utility.rb",
|
|
35
44
|
"spec/Instamojo-rb_spec.rb",
|
|
36
45
|
"spec/spec_helper.rb"
|
|
37
46
|
]
|
|
38
47
|
s.homepage = "http://github.com/AnkurGel/Instamojo-rb"
|
|
39
48
|
s.licenses = ["MIT"]
|
|
40
|
-
s.
|
|
41
|
-
s.rubygems_version = "1.8.23"
|
|
49
|
+
s.rubygems_version = "2.2.2"
|
|
42
50
|
s.summary = "Instamojo Ruby library - Assists you to programmatically create, edit and delete offers on Instamojo"
|
|
43
51
|
|
|
44
52
|
if s.respond_to? :specification_version then
|
|
45
|
-
s.specification_version =
|
|
53
|
+
s.specification_version = 4
|
|
46
54
|
|
|
47
55
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
48
56
|
s.add_runtime_dependency(%q<faraday>, ["= 0.8.8"])
|
|
49
|
-
s.
|
|
50
|
-
s.add_development_dependency(%q<
|
|
57
|
+
s.add_runtime_dependency(%q<rest-client>, ["~> 1.8"])
|
|
58
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.8"])
|
|
51
59
|
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
|
52
|
-
s.add_development_dependency(%q<jeweler>, ["~> 1.8
|
|
53
|
-
s.add_development_dependency(%q<
|
|
54
|
-
s.add_development_dependency(%q<debugger>, [">= 0"])
|
|
60
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8"])
|
|
61
|
+
s.add_development_dependency(%q<debugger>, ["~> 1.6"])
|
|
55
62
|
else
|
|
56
63
|
s.add_dependency(%q<faraday>, ["= 0.8.8"])
|
|
57
|
-
s.add_dependency(%q<
|
|
58
|
-
s.add_dependency(%q<
|
|
64
|
+
s.add_dependency(%q<rest-client>, ["~> 1.8"])
|
|
65
|
+
s.add_dependency(%q<rspec>, ["~> 2.8"])
|
|
59
66
|
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
|
60
|
-
s.add_dependency(%q<jeweler>, ["~> 1.8
|
|
61
|
-
s.add_dependency(%q<
|
|
62
|
-
s.add_dependency(%q<debugger>, [">= 0"])
|
|
67
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8"])
|
|
68
|
+
s.add_dependency(%q<debugger>, ["~> 1.6"])
|
|
63
69
|
end
|
|
64
70
|
else
|
|
65
71
|
s.add_dependency(%q<faraday>, ["= 0.8.8"])
|
|
66
|
-
s.add_dependency(%q<
|
|
67
|
-
s.add_dependency(%q<
|
|
72
|
+
s.add_dependency(%q<rest-client>, ["~> 1.8"])
|
|
73
|
+
s.add_dependency(%q<rspec>, ["~> 2.8"])
|
|
68
74
|
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
|
69
|
-
s.add_dependency(%q<jeweler>, ["~> 1.8
|
|
70
|
-
s.add_dependency(%q<
|
|
71
|
-
s.add_dependency(%q<debugger>, [">= 0"])
|
|
75
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8"])
|
|
76
|
+
s.add_dependency(%q<debugger>, ["~> 1.6"])
|
|
72
77
|
end
|
|
73
78
|
end
|
|
74
79
|
|
data/README.md
CHANGED
|
@@ -1,99 +1,258 @@
|
|
|
1
|
-
#Instamojo-rb
|
|
2
|
-
This is the **Ruby** library of [Instamojo API](
|
|
3
|
-
This will assist you to programmatically create, edit and delete
|
|
1
|
+
# Instamojo-rb
|
|
2
|
+
This is the **Ruby** library of [Instamojo REST API](https://www.instamojo.com/developers/rest/).
|
|
3
|
+
This will assist you to programmatically create, edit and delete links on Instamojo. Also supports [RAP](https://www.instamojo.com/developers/request-a-payment-api/) api for payments request, listing and status.
|
|
4
4
|
|
|
5
|
-
##Installation
|
|
6
|
-
`gem install Instamojo-rb`
|
|
7
|
-
|
|
8
|
-
For your Rails/bundler projects:
|
|
5
|
+
## Installation
|
|
6
|
+
`gem install Instamojo-rb`
|
|
7
|
+
For your Rails/bundler projects:
|
|
9
8
|
`gem 'Instamojo-rb'`
|
|
10
9
|
|
|
11
|
-
##Usage
|
|
12
|
-
|
|
13
|
-
###Set API keys###
|
|
10
|
+
## Usage
|
|
11
|
+
### Set API keys
|
|
14
12
|
```ruby
|
|
15
13
|
require 'Instamojo-rb'
|
|
16
14
|
api = Instamojo::API.new do |app|
|
|
17
|
-
app.
|
|
15
|
+
app.api_key = "api_key-you-received-from-api@instamojo.com"
|
|
16
|
+
app.auth_token = "auth_token-you-received-from-api@instamojo.com"
|
|
18
17
|
end
|
|
19
18
|
#or
|
|
20
|
-
api = Instamojo::API.new("
|
|
19
|
+
api = Instamojo::API.new("api_key-you-received-from-api@instamojo.com", "auth_token-you-received-from-api@instamojo.com")
|
|
21
20
|
```
|
|
22
|
-
|
|
23
|
-
###Generate client:###
|
|
21
|
+
### Generate client
|
|
24
22
|
`client = api.client`
|
|
25
23
|
|
|
26
|
-
|
|
24
|
+
---
|
|
25
|
+
### Links
|
|
26
|
+
|
|
27
|
+
`Link` object contains all the necessary information required to interpret, modify and archive an Instamojo Link. All link operations on client returns one or collectionn of `links`. Original response from Instamojo API for a link is encapsulated in `link.original`, which is immutable. Call `#to_h` on `link` to get it's all attributes.
|
|
28
|
+
_Helper methods_ for `Link`:
|
|
29
|
+
* `link.to_h` - Returns equivalent Ruby hash for a link.
|
|
30
|
+
* `link.to_json` - Returns equivalent JSON for a link
|
|
31
|
+
* `link.original` - Returns original link data fetched from API.
|
|
32
|
+
* `link.save` - Edits updates carried out on Link object at Instamojo.
|
|
33
|
+
* `link.archive` - Archives link at Instamojo
|
|
34
|
+
* `link.reload` or `link.refresh` - Looks for changes on Instamojo server for the link. Immutable
|
|
35
|
+
* `link.reload!` or `link.refresh!` - Same as `link.reload`, but mutable.
|
|
36
|
+
|
|
37
|
+
More about it's usage is below.
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
#### Get Links
|
|
27
41
|
```ruby
|
|
28
|
-
client.
|
|
29
|
-
|
|
30
|
-
client.authenticate do |user|
|
|
31
|
-
user.username = "instamojo_username"
|
|
32
|
-
user.password = "instamojo_password"
|
|
33
|
-
end
|
|
34
|
-
#=> Instamojo Client(URL: https://www.instamojo.com/api/1, Status: Authenticated)
|
|
42
|
+
client.links_list
|
|
43
|
+
#=> Array of Instamojo::Link objects
|
|
35
44
|
```
|
|
36
45
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
`
|
|
46
|
+
#### Create a new link
|
|
47
|
+
##### Required:
|
|
48
|
+
* `title` - Title of the Link, be concise.
|
|
49
|
+
* `description` - Describe what your customers will get, you can add terms and conditions and any other relevant information here. Markdown is supported, popular media URLs like Youtube, Flickr are auto-embedded.
|
|
50
|
+
* `base_price` - Price of the Link. This may be 0, if you want to offer it for free.
|
|
51
|
+
|
|
52
|
+
##### File and Cover image:
|
|
53
|
+
* `file_upload` - Full path to the file you want to sell. This file will be available only after successful payment.
|
|
54
|
+
* `cover_image` - Full path to the IMAGE you want to upload as a cover image.
|
|
55
|
+
|
|
56
|
+
##### Quantity:
|
|
57
|
+
* `quantity` - Set to 0 for unlimited sales. If you set it to say 10, a total of 10 sales will be allowed after which the Link will be made unavailable.
|
|
58
|
+
|
|
59
|
+
##### Post Purchase Note
|
|
60
|
+
* `note` - A post-purchase note, will only displayed after successful payment. Will also be included in the ticket/ receipt that is sent as attachment to the email sent to buyer. This will not be shown if the payment fails.
|
|
40
61
|
|
|
41
|
-
|
|
42
|
-
|
|
62
|
+
##### Event
|
|
63
|
+
* `start_date` - Date-time when the event is beginning. Format: `YYYY-MM-DD HH:mm`
|
|
64
|
+
* `end_date` - Date-time when the event is ending. Format: `YYYY-MM-DD HH:mm`
|
|
65
|
+
* `venue` - Address of the place where the event will be held.
|
|
66
|
+
* `timezone` - Timezone of the venue. Example: Asia/Kolkata
|
|
43
67
|
|
|
68
|
+
##### Redirects and Webhooks
|
|
69
|
+
* `redirect_url` - This can be a Thank-You page on your website. Buyers will be redirected to this page after successful payment.
|
|
70
|
+
* `webhook_url` - Set this to a URL that can accept POST requests made by Instamojo server after successful payment.
|
|
71
|
+
* `enable_pwyw` - set this to True, if you want to enable Pay What You Want. Default is False.
|
|
72
|
+
* `enable_sign` - set this to True, if you want to enable Link Signing. Default is False. For more information regarding this, and to avail this feature write to support at instamojo.com.
|
|
73
|
+
|
|
74
|
+
##### Code:
|
|
44
75
|
```ruby
|
|
45
|
-
client.
|
|
46
|
-
|
|
47
|
-
|
|
76
|
+
new_link = client.create_link do |link|
|
|
77
|
+
link.title = 'API link v1.1'
|
|
78
|
+
link.description = 'Dummy offer via API'
|
|
79
|
+
link.currency = 'INR'
|
|
80
|
+
link.base_price = 0
|
|
81
|
+
link.quantity = 10
|
|
82
|
+
link.redirect_url = 'http://ankurgoel.com'
|
|
83
|
+
link.file_upload = '~/Pictures/RISE.jpg'
|
|
84
|
+
link.cover_image = '~/Pictures/saturday.jpg'
|
|
85
|
+
end
|
|
86
|
+
#=> Instamojo Link(slug: api-link-v11, title: API link v1.1, shorturl: )
|
|
87
|
+
new_link.reload!
|
|
88
|
+
#=> Instamojo Link(slug: api-link-v11, title: API link v1.1, shorturl: http://imojo.in/1dxv1h)
|
|
89
|
+
```
|
|
90
|
+
or
|
|
91
|
+
```ruby
|
|
92
|
+
new_link_params = {base_price: 199, title: 'API link 3', description: 'My dummy offer via API', currency: 'INR', quantity: 20}
|
|
93
|
+
new_link = client.create_link(new_link_params)
|
|
48
94
|
```
|
|
49
95
|
|
|
50
|
-
####
|
|
96
|
+
#### Detail of a link
|
|
51
97
|
```ruby
|
|
52
|
-
client.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
98
|
+
link = client.link_detail('link_slug_goes_here')
|
|
99
|
+
#=> Instamojo Link(slug: link_slug_goes_here, title: Foo Bar, shorturl: http://imojo.in/ankurfoobar)
|
|
100
|
+
link.to_h
|
|
101
|
+
#=> {"title"=>"Foo Bar", "description"=>"", "slug"=>"foo-product", "shorturl"=>"http://imojo.in/ankurfoobar", "url"=>"https://www.instamojo.com/ankurgel/foo-product/", "cover_image"=> "https://www.filepicker.io/api/file/BHeefKAARCKGC5l1J29e/convert?w=500&h=500&fit=clip&quality=70", "currency"=>"INR", "base_price"=>"0.00", "quantity"=>nil, "quantity_sold"=>2, "requires_shipping"=>false, "ships_within_days"=>nil, "start_date"=>nil, "end_date"=>nil, "venue"=>"", "timezone"=>"", "note"=>"", "redirect_url"=>"", "webhook_url"=>"", "status"=>"Live", "enable_pwyw"=>false, "enable_sign"=>false, "socialpay_platforms"=>""}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
#### Edit a link
|
|
105
|
+
```ruby
|
|
106
|
+
link = client.links_list.first
|
|
107
|
+
link.save do |l|
|
|
108
|
+
l.title = "Foo"
|
|
109
|
+
l.description = "This new information should go in link"
|
|
58
110
|
end
|
|
111
|
+
#=> Returns updated Link object from Instamojo
|
|
112
|
+
```
|
|
113
|
+
or
|
|
114
|
+
```ruby
|
|
115
|
+
link = client.link_detail('foo-product')
|
|
116
|
+
link.title = 'Foo'; link.description = 'This new information should go in link'
|
|
117
|
+
link.save
|
|
118
|
+
# returns updated Link object from Instamojo
|
|
119
|
+
```
|
|
120
|
+
or handle it directly without Link object
|
|
121
|
+
```ruby
|
|
122
|
+
client.edit_link({slug: 'foo-product', title: 'Foo', description: 'This new infromation should go in link'})
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
### Payments
|
|
127
|
+
`Payment` object contains the necessary information such as `payment_id`, `quantity`, `status`, `buyer_email` etc. Call `#to_h` on `payment` to get it's all attributes. `Payment` object has following helpers:
|
|
128
|
+
- `payment.to_h` - Returns equivalent Ruby hash for a payment
|
|
129
|
+
- `payment.to_json` - Returns equivalent JSON for a payment
|
|
130
|
+
- `payment.original` - Returns original payment data fetched from API.
|
|
131
|
+
- Like `Link`, it also exposes `reload` and `reload!`
|
|
59
132
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
133
|
+
Details are documented [here](https://www.instamojo.com/developers/rest/#toc-payments)
|
|
134
|
+
|
|
135
|
+
#### Get Payments
|
|
136
|
+
```ruby
|
|
137
|
+
client.payments_list
|
|
138
|
+
#=> Returns array of Payment objects
|
|
139
|
+
```
|
|
140
|
+
#### Detail or status of a payment
|
|
141
|
+
```ruby
|
|
142
|
+
payment = client.payment_detail('MOJxxx06000F97367750')
|
|
143
|
+
#=> Instamojo Payment(payment_id: MOJxxx06000F97367750, quantity: 1, amount: 0.00, status: Credit, link_slug: api-link-7-node, buyer_name: Ankur Goel)
|
|
144
|
+
payment.to_h
|
|
145
|
+
#=> Hash of all payment object attributes
|
|
68
146
|
```
|
|
147
|
+
#### Request a payment
|
|
148
|
+
This is a part of [RAP API](https://www.instamojo.com/developers/request-a-payment-api/). You can request a payment from anyone via this who will then be notified to make a payment with specified payment. The payment then can be carried out via [Instapay](https://www.instamojo.com/pay/). Jump over to the documentation to see accepted parameters.
|
|
149
|
+
##### Code:
|
|
150
|
+
```ruby
|
|
151
|
+
payment_request = client.payment_request({amount:100, purpose: 'api', send_email: true, email: 'ankurgel+2@gmail.com', redirect_url: 'http://ankurgoel.com'})
|
|
152
|
+
#=> Instamojo PaymentRequest(id: 8726f8c5001e426f8b24e908b2761686, purpose: api, amount: 100.00, status: Sent, shorturl: , longurl: https://www.instamojo.com/@ashwini/8726f8c5001e426f8b24e908b2761686)
|
|
153
|
+
```
|
|
154
|
+
#### Get Payment Requests
|
|
155
|
+
```ruby
|
|
156
|
+
payment_requests = client.payment_requests_list
|
|
157
|
+
#=> Returns array of PaymentRequest objects
|
|
158
|
+
```
|
|
159
|
+
#### Status of payment request
|
|
160
|
+
You can get the status of a payment_request from the id you obtained after making payment request.
|
|
161
|
+
```ruby
|
|
162
|
+
payment_request.reload!
|
|
163
|
+
#or
|
|
164
|
+
payment_request = client.payment_request_status('8726f8c5001e426f8b24e908b2761686')
|
|
165
|
+
#=> Instamojo PaymentRequest(id: 8726f8c5001e426f8b24e908b2761686, purpose: api, amount: 100.00, status: Sent, shorturl: http://imjo.in/Nasdf , longurl: https://www.instamojo.com/@ashwini/8726f8c5001e426f8b24e908b2761686)
|
|
166
|
+
```
|
|
167
|
+
---
|
|
168
|
+
### Refunds
|
|
169
|
+
`Refund` object contains the necessary information such as `payment_id`, `refund_amount`, `status` and `body` etc. Call `#to_h` on `refund` to get it's all attributes. `Refund` object has the same helpers as `Payment` above, including `reload` and `reload!`.
|
|
69
170
|
|
|
70
|
-
####
|
|
71
|
-
|
|
171
|
+
#### Get Refunds
|
|
172
|
+
```ruby
|
|
173
|
+
refunds = client.refunds_list
|
|
174
|
+
#=> Returns array of Refund objects
|
|
175
|
+
```
|
|
72
176
|
|
|
73
|
-
|
|
74
|
-
|
|
177
|
+
#### Create a new refund
|
|
178
|
+
##### Required:
|
|
179
|
+
* `payment_id` - Payment ID of the payment against which you're initiating the refund.
|
|
180
|
+
* `type` - A three letter short-code identifying the [reason for this case](https://www.instamojo.com/developers/rest/#toc-refunds).
|
|
181
|
+
* `body` - Additonal text explaining the refund.
|
|
75
182
|
|
|
183
|
+
```ruby
|
|
184
|
+
client.create_refund({payment_id: 'MOJO5c04000J30502939', type: 'QFL', body: 'Customer is not satisfied'})
|
|
185
|
+
#=> Returns Refund object or non-200 response object
|
|
186
|
+
```
|
|
187
|
+
or
|
|
188
|
+
```ruby
|
|
189
|
+
client.create_refund do |refund|
|
|
190
|
+
refund.payment_id = 'MOJO5c04000J30502939'
|
|
191
|
+
refund.type = 'QFL'
|
|
192
|
+
refund.body = 'Customer is not satisifed'
|
|
193
|
+
end
|
|
194
|
+
```
|
|
195
|
+
or refund a `payment` directly:
|
|
196
|
+
```ruby
|
|
197
|
+
payment = client.payment_detail('MOJO5c05000F97367750')
|
|
198
|
+
payment.process_refund(type: 'QFL', body: 'User wanted different version') #or
|
|
199
|
+
payment.process_refund do |refund|
|
|
200
|
+
refund.type = 'QFL'
|
|
201
|
+
refund.body = 'User wanted different version'
|
|
202
|
+
end
|
|
203
|
+
```
|
|
76
204
|
|
|
77
|
-
|
|
205
|
+
#### Details of a refund
|
|
206
|
+
```ruby
|
|
207
|
+
refund = client.refund_detail 'C5c0751269'
|
|
208
|
+
#=> Instamojo Refund(id: C5c0751269, status: 'Refunded' payment_id: MOJO5c04000J30502939, refund_amount: 100)
|
|
209
|
+
refund.to_h
|
|
210
|
+
#=> Hash of all refund attributes
|
|
211
|
+
refund.reload!
|
|
212
|
+
#=> Updates the refund from server
|
|
213
|
+
#=> Instamojo Refund(id: C5c0751269, status: 'Closed' payment_id: MOJO5c04000J30502939, refund_amount: 100)
|
|
214
|
+
```
|
|
215
|
+
or
|
|
216
|
+
```ruby
|
|
217
|
+
refunds = client.refunds_list
|
|
218
|
+
refund = refunds.last
|
|
219
|
+
refund.reload #=> refetches the refund from server
|
|
220
|
+
#=> Instamojo Refund(id: C5c0751269, status: 'Refunded' payment_id: MOJO5c04000J30502939, refund_amount: 100)
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
### Authentication
|
|
225
|
+
```ruby
|
|
226
|
+
client.authenticate('instamojo_username', 'instamojo_password')
|
|
227
|
+
#or
|
|
228
|
+
client.authenticate do |user|
|
|
229
|
+
user.username = "instamojo_username"
|
|
230
|
+
user.password = "instamojo_password"
|
|
231
|
+
end
|
|
232
|
+
#=> Instamojo Client(URL: https://www.instamojo.com/api/1, Status: Authenticated)
|
|
233
|
+
```
|
|
234
|
+
#### Logout
|
|
235
|
+
```ruby
|
|
236
|
+
client.logout
|
|
237
|
+
```
|
|
238
|
+
---
|
|
239
|
+
### Misc
|
|
240
|
+
* `client.authorized` - View last status of api client request.
|
|
241
|
+
* `client.response` - View last procured response by client.
|
|
242
|
+
* `client.response.code` - View `response_code` of last request sent by client.
|
|
78
243
|
|
|
79
|
-
|
|
244
|
+
#### Logging
|
|
245
|
+
If you are interested in seeing api requests being made to Instamojo server. Flip this flag: `Instamojo::DEBUG = true` and genereate the api client again.
|
|
80
246
|
|
|
81
|
-
* Error handling; with respect to `Instamojo` error codes.
|
|
82
|
-
* File Upload support.
|
|
83
|
-
* `Offer` and `Event` model with api methods like
|
|
84
|
-
+ _Accessor_ methods like on `Offer`: `#title`, `#description`, `#quantity`
|
|
85
|
-
+ `offer.set_title('Changed offer title')`
|
|
86
|
-
+ `offer.set_quantity(30)`
|
|
87
|
-
+ `offer.enable_variants`
|
|
88
247
|
|
|
89
|
-
##Contributing
|
|
248
|
+
## Contributing
|
|
90
249
|
|
|
91
250
|
* [Fork](https://github.com/AnkurGel/Instamojo-rb/fork) the project
|
|
92
251
|
* `bundle install` to satisfy gem dependencies.
|
|
93
|
-
* `rake install` to install the gem.
|
|
94
|
-
* Swim around in `lib/`.
|
|
252
|
+
* `rake install` to install the gem.
|
|
253
|
+
* Swim around in `lib/`.
|
|
95
254
|
|
|
96
|
-
##Copyright
|
|
255
|
+
## Copyright
|
|
97
256
|
|
|
98
257
|
Copyright (c) 2014 Ankur Goel.
|
|
99
258
|
|