From ade415f9d2051bffb71ee4b3eb8844a1a01577e2 Mon Sep 17 00:00:00 2001 From: Ashwini Chaudhary Date: Fri, 11 Dec 2015 11:34:10 +0530 Subject: [PATCH 1/7] Fixed payment detail endpoint to use the correct class. --- lib/client/client.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/client/client.rb b/lib/client/client.rb index 588267f..3179561 100644 --- a/lib/client/client.rb +++ b/lib/client/client.rb @@ -132,7 +132,7 @@ 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 end # POST /payment-requests From b2f7e20358ffcee7cc4af0e65aa498fe34238917 Mon Sep 17 00:00:00 2001 From: Ashwini Chaudhary Date: Fri, 11 Dec 2015 12:26:54 +0530 Subject: [PATCH 2/7] Added a class for Payment Request as well --- lib/client/payment_request.rb | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 lib/client/payment_request.rb diff --git a/lib/client/payment_request.rb b/lib/client/payment_request.rb new file mode 100644 index 0000000..91f8bcd --- /dev/null +++ b/lib/client/payment_request.rb @@ -0,0 +1,46 @@ +module Instamojo + +=begin Example +{ + "id" => "92e58bd771414d05a5e443b0a85f8b43", + "phone" => "+919999999999", + "email" => "foo@example.com", + "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 Payment Request(id: %s, purpose: %s, amount: %s, status: %s, shorturl: %s, longurl: %s)", + id, purpose, amount, status, shorturl, longurl) + end + end +end \ No newline at end of file From 7e5c83e82dc343f69b8686d34d60fd65d22d9908 Mon Sep 17 00:00:00 2001 From: Ashwini Chaudhary Date: Fri, 11 Dec 2015 12:27:47 +0530 Subject: [PATCH 3/7] Added payment_request to gemspec and the base imports --- Instamojo-rb.gemspec | 1 + lib/Instamojo-rb.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/Instamojo-rb.gemspec b/Instamojo-rb.gemspec index 0a1d88d..c4b2cbb 100644 --- a/Instamojo-rb.gemspec +++ b/Instamojo-rb.gemspec @@ -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", diff --git a/lib/Instamojo-rb.rb b/lib/Instamojo-rb.rb index a00b2bb..4e9646a 100644 --- a/lib/Instamojo-rb.rb +++ b/lib/Instamojo-rb.rb @@ -12,3 +12,4 @@ require_relative 'client/payment' require_relative 'client/refund' require_relative 'client/client' +require_relative 'client/payment_request' From fd9190f404cbc6b05b1893840e761a2b156a6be7 Mon Sep 17 00:00:00 2001 From: Ashwini Chaudhary Date: Fri, 11 Dec 2015 12:28:15 +0530 Subject: [PATCH 4/7] Payment Request endpoints are now using the PaymentRequest class --- lib/client/client.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/client/client.rb b/lib/client/client.rb index 3179561..ed07661 100644 --- a/lib/client/client.rb +++ b/lib/client/client.rb @@ -139,19 +139,20 @@ def payment_detail(payment_id) 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') From b7f78b570bd210aa1b13973181a7f8436a6122ea Mon Sep 17 00:00:00 2001 From: Ashwini Chaudhary Date: Fri, 11 Dec 2015 12:35:29 +0530 Subject: [PATCH 5/7] Removed the space --- lib/client/payment_request.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/client/payment_request.rb b/lib/client/payment_request.rb index 91f8bcd..4877d79 100644 --- a/lib/client/payment_request.rb +++ b/lib/client/payment_request.rb @@ -39,7 +39,7 @@ def initialize(payment_request, client) end def to_s - sprintf("Instamojo Payment Request(id: %s, purpose: %s, amount: %s, status: %s, shorturl: %s, longurl: %s)", + sprintf("Instamojo PaymentRequest(id: %s, purpose: %s, amount: %s, status: %s, shorturl: %s, longurl: %s)", id, purpose, amount, status, shorturl, longurl) end end From 75c9383ff9175764a105dda9fb5500314610c103 Mon Sep 17 00:00:00 2001 From: Ashwini Chaudhary Date: Fri, 11 Dec 2015 12:35:41 +0530 Subject: [PATCH 6/7] Updated README --- README.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ff61d01..138685f 100644 --- a/README.md +++ b/README.md @@ -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: 'ankurgel+2@gmail.com', 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: 'ankurgel+2@gmail.com', 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: , longurl: https://www.instamojo. ``` --- ### Refunds From 8df0f7f1ce2924048a5a344c3a74459120d5d579 Mon Sep 17 00:00:00 2001 From: Ashwini Chaudhary Date: Fri, 11 Dec 2015 12:46:33 +0530 Subject: [PATCH 7/7] Copy-paste miftake --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 138685f..eb2f3a4 100644 --- a/README.md +++ b/README.md @@ -155,7 +155,7 @@ response = client.payment_requests_list You can get the status of a payment_request from the id you obtained after making payment request. ```ruby payment_request = client.payment_request_status('8726f8c5001e426f8b24e908b2761686') -#=> #=> Instamojo PaymentRequest(id: 8726f8c5001e426f8b24e908b2761686, purpose: api, amount: 100.00, status: Sent, shorturl: , longurl: https://www.instamojo. +#=> Instamojo PaymentRequest(id: 8726f8c5001e426f8b24e908b2761686, purpose: api, amount: 100.00, status: Sent, shorturl: http://imjo.in/Nasdf , longurl: https://www.instamojo.com/@ashwini/8726f8c5001e426f8b24e908b2761686) ``` --- ### Refunds