Skip to content

Commit ad3ca2b

Browse files
committed
Merge pull request #4 from ashwch/1.1-improvements
1.1 improvements for #2
2 parents 1de99b7 + 8df0f7f commit ad3ca2b

File tree

5 files changed

+57
-10
lines changed

5 files changed

+57
-10
lines changed

Instamojo-rb.gemspec

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Gem::Specification.new do |s|
3737
"lib/client/link.rb",
3838
"lib/client/payment.rb",
3939
"lib/client/refund.rb",
40+
"lib/client/payment_request.rb",
4041
"lib/common_object.rb",
4142
"lib/response.rb",
4243
"lib/utility.rb",

README.md

+5-7
Original file line numberDiff line numberDiff line change
@@ -143,21 +143,19 @@ payment.to_h
143143
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.
144144
##### Code:
145145
```ruby
146-
payment = client.payment_request({amount:100, purpose: 'api', send_email: true, email: '[email protected]', redirect_url: 'http://ankurgoel.com'})
147-
#=> Returns response of payment request.
148-
p client.response.body[:payment_request]
149-
#=> Print status & details of payment_request. Details will also contain unique id which can be used to request the status of payment request later.
146+
payment_request = client.payment_request({amount:100, purpose: 'api', send_email: true, email: '[email protected]', redirect_url: 'http://ankurgoel.com'})
147+
#=> Instamojo PaymentRequest(id: 8726f8c5001e426f8b24e908b2761686, purpose: api, amount: 100.00, status: Sent, shorturl: , longurl: https://www.instamojo.com/@ashwini/8726f8c5001e426f8b24e908b2761686)
150148
```
151149
#### Get Payment Requests
152150
```ruby
153151
response = client.payment_requests_list
154-
#=> Returns response for all payment_requests with their status
152+
#=> Returns array of PaymentRequest objects
155153
```
156154
#### Status of payment request
157155
You can get the status of a payment_request from the id you obtained after making payment request.
158156
```ruby
159-
client.payment_request_status('payment_request_id_goes_here')
160-
#=> Returns response containing the status of payment request.
157+
payment_request = client.payment_request_status('8726f8c5001e426f8b24e908b2761686')
158+
#=> Instamojo PaymentRequest(id: 8726f8c5001e426f8b24e908b2761686, purpose: api, amount: 100.00, status: Sent, shorturl: http://imjo.in/Nasdf , longurl: https://www.instamojo.com/@ashwini/8726f8c5001e426f8b24e908b2761686)
161159
```
162160
---
163161
### Refunds

lib/Instamojo-rb.rb

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
require_relative 'client/payment'
1313
require_relative 'client/refund'
1414
require_relative 'client/client'
15+
require_relative 'client/payment_request'

lib/client/client.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -132,26 +132,27 @@ def payments_list
132132
# GET /payments/:payment_id
133133
def payment_detail(payment_id)
134134
get("payments/#{payment_id}")
135-
@response.success? ? Instamojo::Link.new(@response.body[:payment], self) : @response
135+
@response.success? ? Instamojo::Payment.new(@response.body[:payment], self) : @response
136136
end
137137

138138
# POST /payment-requests
139139
def payment_request(options, &block)
140140
set_options(options, &block)
141141
post('payment-requests', options)
142-
@response
142+
@response.success? ? Instamojo::PaymentRequest.new(@response.body[:payment_request], self) : @response
143143
end
144144

145145
# GET /payment-requests
146146
def payment_requests_list
147147
get('payment-requests')
148+
@response.success? ? @response.body[:payment_requests].map { |payment_request| Instamojo::PaymentRequest.new payment_request, self } : @response
148149
end
149150

150151
def payment_request_status(payment_request_id)
151152
get("payment-requests/#{payment_request_id}") if payment_request_id
153+
@response.success? ? Instamojo::PaymentRequest.new(@response.body[:payment_request], self) : @response
152154
end
153155

154-
155156
# GET /refunds
156157
def refunds_list
157158
get('refunds')

lib/client/payment_request.rb

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
module Instamojo
2+
3+
=begin Example
4+
{
5+
"id" => "92e58bd771414d05a5e443b0a85f8b43",
6+
"phone" => "+919999999999",
7+
"email" => "[email protected]",
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+
33+
def initialize(payment_request, client)
34+
@original = payment_request
35+
payment_request.each do |k, v|
36+
instance_variable_set("@#{k}", v)
37+
end
38+
@client = client # Reference to client
39+
end
40+
41+
def to_s
42+
sprintf("Instamojo PaymentRequest(id: %s, purpose: %s, amount: %s, status: %s, shorturl: %s, longurl: %s)",
43+
id, purpose, amount, status, shorturl, longurl)
44+
end
45+
end
46+
end

0 commit comments

Comments
 (0)