Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.1 improvements #4

Merged
merged 7 commits into from
Dec 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Instamojo-rb.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Gem::Specification.new do |s|
"lib/client/link.rb",
"lib/client/payment.rb",
"lib/client/refund.rb",
"lib/client/payment_request.rb",
"lib/common_object.rb",
"lib/response.rb",
"lib/utility.rb",
Expand Down
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,21 +143,19 @@ payment.to_h
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.
##### Code:
```ruby
payment = client.payment_request({amount:100, purpose: 'api', send_email: true, email: '[email protected]', redirect_url: 'http://ankurgoel.com'})
#=> Returns response of payment request.
p client.response.body[:payment_request]
#=> Print status & details of payment_request. Details will also contain unique id which can be used to request the status of payment request later.
payment_request = client.payment_request({amount:100, purpose: 'api', send_email: true, email: '[email protected]', redirect_url: 'http://ankurgoel.com'})
#=> Instamojo PaymentRequest(id: 8726f8c5001e426f8b24e908b2761686, purpose: api, amount: 100.00, status: Sent, shorturl: , longurl: https://www.instamojo.com/@ashwini/8726f8c5001e426f8b24e908b2761686)
```
#### Get Payment Requests
```ruby
response = client.payment_requests_list
#=> Returns response for all payment_requests with their status
#=> Returns array of PaymentRequest objects
```
#### Status of payment request
You can get the status of a payment_request from the id you obtained after making payment request.
```ruby
client.payment_request_status('payment_request_id_goes_here')
#=> Returns response containing the status of payment request.
payment_request = client.payment_request_status('8726f8c5001e426f8b24e908b2761686')
#=> Instamojo PaymentRequest(id: 8726f8c5001e426f8b24e908b2761686, purpose: api, amount: 100.00, status: Sent, shorturl: http://imjo.in/Nasdf , longurl: https://www.instamojo.com/@ashwini/8726f8c5001e426f8b24e908b2761686)
```
---
### Refunds
Expand Down
1 change: 1 addition & 0 deletions lib/Instamojo-rb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
require_relative 'client/payment'
require_relative 'client/refund'
require_relative 'client/client'
require_relative 'client/payment_request'
7 changes: 4 additions & 3 deletions lib/client/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,26 +132,27 @@ def payments_list
# GET /payments/:payment_id
def payment_detail(payment_id)
get("payments/#{payment_id}")
@response.success? ? Instamojo::Link.new(@response.body[:payment], self) : @response
@response.success? ? Instamojo::Payment.new(@response.body[:payment], self) : @response
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

damn! my bad 😆

end

# POST /payment-requests
def payment_request(options, &block)
set_options(options, &block)
post('payment-requests', options)
@response
@response.success? ? Instamojo::PaymentRequest.new(@response.body[:payment_request], self) : @response
end

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

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


# GET /refunds
def refunds_list
get('refunds')
Expand Down
46 changes: 46 additions & 0 deletions lib/client/payment_request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module Instamojo

=begin Example
{
"id" => "92e58bd771414d05a5e443b0a85f8b43",
"phone" => "+919999999999",
"email" => "[email protected]",
"buyer_name" => "John Doe",
"amount" => "2500",
"purpose" => "FIFA 16",
"status" => "Pending",
"send_sms" => true,
"send_email" => true,
"sms_status" => "Pending",
"email_status" => "Pending",
"shorturl" => nil,
"longurl" => "https://www.instamojo.com/@ashwini/92e58bd771414d05a5e443b0a85f8b43",
"redirect_url" => "http://www.example.com/redirect/",
"webhook" => "http://www.example.com/webhook/",
"created_at" => "2015-10-07T21:36:34.665Z",
"modified_at" => "2015-10-07T21:36:34.665Z",
"allow_repeated_payments" => false
}
=end

class PaymentRequest
attr_accessor :id, :phone, :email, :buyer_name, :amount, :purpose, :status, :send_sms, :send_email, :sms_status
attr_accessor :email_status, :shorturl, :longurl, :redirect_url, :webhook, :created_at, :modified_at, :allow_repeated_payments

attr_reader :original
include CommonObject

def initialize(payment_request, client)
@original = payment_request
payment_request.each do |k, v|
instance_variable_set("@#{k}", v)
end
@client = client # Reference to client
end

def to_s
sprintf("Instamojo PaymentRequest(id: %s, purpose: %s, amount: %s, status: %s, shorturl: %s, longurl: %s)",
id, purpose, amount, status, shorturl, longurl)
end
end
end