razorpay 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dce82913804bb88aa43d0d55864f8530f1ff89c1
4
+ data.tar.gz: fcd77dc50fe72a7bb518b69a213e91f94a41b0e6
5
+ SHA512:
6
+ metadata.gz: db02004ab7c0874f3c143488c917012040342cbfd0176f423604509c3c5bea624ded847c278788798398d940c2a39719417f261ade40ba4db8db9959b2850c78
7
+ data.tar.gz: a8cd65b6e4e41c98e2ed079edcd09ec5c39ed90cef32919322c332080bc123f1e5ac4ab1f2dda66d871b25b2a23c923df2f1c9b215ec79e14c4e193ab56dda0e
data/.editorconfig ADDED
@@ -0,0 +1,12 @@
1
+ ; This file is for unifying the coding style for different editors and IDEs.
2
+ ; More information at http://EditorConfig.org
3
+
4
+ root = true
5
+ ; Use 2 spaces for indentation in all files
6
+ [*]
7
+ end_of_line = lf
8
+ charset = utf-8
9
+ trim_trailing_whitespace = true
10
+ indent_style = space
11
+ indent_size = 2
12
+ insert_final_newline = true
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ Metrics/AbcSize:
2
+ Max: 18
3
+
4
+ # Configuration parameters: AllowURI, URISchemes.
5
+ Metrics/LineLength:
6
+ Max: 110
7
+ AllowURI: true
8
+
9
+ Style/ClassVars:
10
+ Enabled: false
11
+
12
+ Metrics/MethodLength:
13
+ Max: 15
data/.simplecov ADDED
@@ -0,0 +1,4 @@
1
+ SimpleCov.start do
2
+ add_filter "test"
3
+ command_name "Minitest"
4
+ end
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby # Auto-detected as well
2
+ rvm:
3
+ - "1.9.3"
4
+ - "2.0.0"
5
+ - "2.1.1"
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in razorpay-ruby.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Razorpay
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # Razorpay Ruby bindings
2
+
3
+ [![Build Status](https://travis-ci.org/Razorpay/razorpay-ruby.svg?branch=master)](https://travis-ci.org/Razorpay/razorpay-ruby)
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/razorpay.svg)](http://badge.fury.io/rb/razorpay)
6
+
7
+ This is the base ruby gem for interacting with the Razorpay API. This is primarily meant for merchants who wish to perform interactions with the Razorpay API programatically.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'razorpay'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install razorpay
22
+
23
+ ## Usage
24
+
25
+ Remember to `require razorpay` before anything else.
26
+
27
+ Next, you need to setup your key and secret using the following:
28
+
29
+ Razorpay.setup("merchant_key_id", "merchant_key_secret")
30
+
31
+ You can find your API keys at <https://dashboard.razorpay.com/#/app/keys>.
32
+
33
+ If you are using rails, the right place to do this might be `config/initializers/razorpay.rb`.
34
+
35
+ The most common construct is capturing a payment, which you do via the following:
36
+
37
+ Razorpay::Payment.fetch("pay-ment_id").capture({amount:500})
38
+ # Note that the amount should come from your session, so as to verify
39
+ # that the purchase was correctly done and not tampered
40
+
41
+ You can handle refunds using the following constructs:
42
+
43
+ Razorpay::Payment.fetch("pay-ment_id").refund({amount:500})
44
+
45
+ For other applications (such as fetching payments and refunds),
46
+ see our online documentation on <https://docs.razorpay.com>
47
+
48
+ ## Development
49
+
50
+ - Everything is namespaced under the Razorpay module
51
+ - We use rubocop for checking style guidelines
52
+ - Rake + MiniTest is using as the testrunner
53
+ - Webmock is used as the request mock framework
54
+ - HTTParty is used for making requests
55
+ - Travis is used for CI
56
+ - Coveralls is used for coverage reports
57
+
58
+ ## Contributing
59
+
60
+ 1. Fork it ( https://github.com/razorpay/razorpay-ruby/fork )
61
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
62
+ 3. Run `rake` and `rubocop` after making your changes to make sure you didn't break anything
63
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
64
+ 5. Push to the branch (`git push origin my-new-feature`)
65
+ 6. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ t.pattern = 'test/razorpay/test_*.rb'
6
+ end
7
+
8
+ desc 'Run tests'
9
+ task default: :test
data/lib/razorpay.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'razorpay/constants'
2
+ require 'razorpay/payment'
3
+
4
+ # Base Razorpay module
5
+ module Razorpay
6
+ class << self
7
+ attr_accessor :auth
8
+ end
9
+
10
+ def self.setup(key_id, key_secret)
11
+ self.auth = { username: key_id, password: key_secret }
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ module Razorpay
2
+ # Collection class handles groups of similar
3
+ # entities
4
+ class Collection < Entity
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ # Version and other constants are defined here
2
+ module Razorpay
3
+ BASE_URI = 'https://api.razorpay.com/v1/'
4
+ VERSION = '1.0.0'
5
+ end
@@ -0,0 +1,30 @@
1
+ require 'json'
2
+
3
+ module Razorpay
4
+ # Entity class is the base class for all Razorpay objects
5
+ # This saves data in a hash internally, and makes it available
6
+ # via direct methods
7
+ class Entity
8
+ def initialize(attributes)
9
+ @attributes = attributes
10
+ end
11
+
12
+ # This method fakes attr_reader, but uses
13
+ # the @attributes hash as the source, instead of
14
+ # instance variables
15
+ def method_missing(name)
16
+ name = name.to_s
17
+ if @attributes.key?(name)
18
+ @attributes[name]
19
+ else
20
+ fail NameError, "No such data member: #{name}"
21
+ end
22
+ end
23
+
24
+ # Public: Convert the Entity object to JSON
25
+ # Returns the JSON representation of the Entity (as a string)
26
+ def to_json
27
+ @attributes.to_json
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,4 @@
1
+ require 'razorpay/errors/razorpay_error'
2
+ require 'razorpay/errors/bad_request_error'
3
+ require 'razorpay/errors/gateway_error'
4
+ require 'razorpay/errors/server_error'
@@ -0,0 +1,14 @@
1
+ require 'razorpay/errors/razorpay_error'
2
+
3
+ module Razorpay
4
+ # Bad request to API. Missing a field or an invalid field.
5
+ # Error in merchant request. Check the description and correct the request accordingly.
6
+ class BadRequestError < Razorpay::Error
7
+ attr_reader :field
8
+
9
+ def initialize(code, status, field = nil)
10
+ super(code, status)
11
+ @field = field
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ require 'razorpay/errors/razorpay_error'
2
+
3
+ module Razorpay
4
+ # Error in Gateway Communication.
5
+ class GatewayError < Razorpay::Error
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module Razorpay
2
+ # Default Error class for any unknown errors
3
+ class Error < StandardError
4
+ attr_reader :code, :status
5
+
6
+ def initialize(code, status)
7
+ @code = code
8
+ @status = status
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ require 'razorpay/errors/razorpay_error'
2
+
3
+ module Razorpay
4
+ # There is some problem with the server
5
+ class ServerError < Razorpay::Error
6
+ end
7
+ end
@@ -0,0 +1,36 @@
1
+ require 'razorpay/request'
2
+ require 'razorpay/refund'
3
+ require 'razorpay/entity'
4
+
5
+ module Razorpay
6
+ # Payment class is the most commonly used class
7
+ # and is used to interact with Payments, the most
8
+ # common type of transactions
9
+ class Payment < Entity
10
+ def self.request
11
+ Razorpay::Request.new('payments')
12
+ end
13
+
14
+ def self.fetch(id)
15
+ request.fetch id
16
+ end
17
+
18
+ def self.all(options = {})
19
+ request.all options
20
+ end
21
+
22
+ def refund(options = {})
23
+ self.class.request.post "#{id}/refund", options
24
+ end
25
+
26
+ def refunds
27
+ # This needs to be a string, not a symbol
28
+ Refund.new('payment_id' => id)
29
+ end
30
+
31
+ def capture(options)
32
+ fail ArgumentError, 'Please provide capture amount' unless options.key?(:amount)
33
+ self.class.request.post "#{id}/capture", options
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,22 @@
1
+ require 'razorpay'
2
+ require 'razorpay/request'
3
+ require 'razorpay/entity'
4
+
5
+ module Razorpay
6
+ # Refund class handles all refund objects
7
+ class Refund < Entity
8
+ def initialize(data)
9
+ super
10
+ @request = Razorpay::Request.new("payments/#{payment_id}/refunds")
11
+ end
12
+
13
+ def all(options = {})
14
+ # We receive an array of item hashes
15
+ @request.all options
16
+ end
17
+
18
+ def fetch(id)
19
+ @request.fetch id
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,73 @@
1
+ require 'razorpay'
2
+ require 'httparty'
3
+
4
+ module Razorpay
5
+ # Request objects are used to create fetch
6
+ # objects, which make requests to the server
7
+ # using HTTParty
8
+ class Request
9
+ include HTTParty
10
+
11
+ def initialize(entity_name)
12
+ self.class.base_uri(Razorpay::BASE_URI)
13
+ @entity_name = entity_name
14
+ end
15
+
16
+ def fetch(id)
17
+ request :get, "/#{@entity_name}/#{id}"
18
+ end
19
+
20
+ def all(options)
21
+ request :get, "/#{@entity_name}", options
22
+ end
23
+
24
+ def post(url, data = {})
25
+ request :post, "/#{@entity_name}/#{url}", data
26
+ end
27
+
28
+ def request(method, url, data = {})
29
+ case method
30
+ when :get
31
+ create_instance self.class.send(method, url, query: data, basic_auth: Razorpay.auth)
32
+ when :post
33
+ create_instance self.class.send(method, url, body: data, basic_auth: Razorpay.auth)
34
+ end
35
+ end
36
+
37
+ # Recursively builds entity instances
38
+ # out of all hashes in the response object
39
+ def create_instance(res)
40
+ response = res.parsed_response
41
+
42
+ # if there was an error, throw it
43
+ raise_error(response['error'], res.code) if response.key?('error')
44
+
45
+ # There must be a top level entity
46
+ # This is either one of payment, refund, or collection at present
47
+ class_name = response['entity'].capitalize
48
+ begin
49
+ klass = Razorpay.const_get class_name
50
+ rescue NameError
51
+ # Use Entity class if we don't find any
52
+ klass = Razorpay::Entity
53
+ end
54
+ klass.new(response)
55
+ end
56
+
57
+ def raise_error(error, status)
58
+ # Get the error class name, require it and instantiate an error
59
+ require "razorpay/#{error['code'].downcase}"
60
+ class_name = 'Razorpay::' + error['code'].split('_').map(&:capitalize).join('')
61
+ args = [error['code'], status]
62
+ args.push error['field'] if error.key?('field')
63
+ klass =
64
+ begin
65
+ Object.const_get(class_name)
66
+ # We got an unknown error, cast it to Error for now
67
+ rescue NameError
68
+ Razorpay::Error
69
+ end
70
+ fail klass.new(*args), error['description']
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'razorpay/constants'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'razorpay'
8
+ spec.version = Razorpay::VERSION
9
+ spec.authors = ['Abhay Rana']
10
+ spec.email = ['nemo@razorpay.com']
11
+ spec.summary = "Razorpay's Ruby API"
12
+ spec.description = 'Official ruby bindings for the Razorpay API'
13
+ spec.homepage = 'https://github.com/razorpay/razorpay-ruby'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split("\n")
17
+ spec.executables = spec.files.grep(/^bin/) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(/^(test|spec|features)/)
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.6'
22
+ spec.add_development_dependency 'rake', '~> 10.4'
23
+ spec.add_development_dependency 'minitest', '~> 5.5'
24
+ spec.add_development_dependency 'webmock', '~> 1.20'
25
+ spec.add_development_dependency 'simplecov', '~> 0.9'
26
+ spec.add_dependency 'httparty', '~> 0.13'
27
+ end
@@ -0,0 +1,13 @@
1
+ {
2
+ "id": "pay_29QQoUBi66xm2f",
3
+ "entity": "payment",
4
+ "amount": 500,
5
+ "currency": "INR",
6
+ "status": "captured",
7
+ "amount_refunded": 0,
8
+ "refund_status": null,
9
+ "error_code": null,
10
+ "error_description": null,
11
+ "udf": {},
12
+ "created_at": 1400826750
13
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "id": "fake_payment_id",
3
+ "entity": "payment",
4
+ "amount": 500,
5
+ "currency": "INR",
6
+ "status": "created",
7
+ "amount_refunded": 0,
8
+ "refund_status": null,
9
+ "error_code": null,
10
+ "error_description": null,
11
+ "udf": {},
12
+ "created_at": 1400826750
13
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "id": "fake_refund_id",
3
+ "entity": "refund",
4
+ "amount": 2000,
5
+ "currency": "INR",
6
+ "payment_id": "fake_payment_id",
7
+ "created_at": 1500826750
8
+ }
@@ -0,0 +1,32 @@
1
+ {
2
+ "count": 2,
3
+ "entity": "collection",
4
+ "items": [
5
+ {
6
+ "id": "pay_29QQoUBi66xm2f",
7
+ "entity": "payment",
8
+ "amount": 500,
9
+ "currency": "INR",
10
+ "status": "created",
11
+ "amount_refunded": 0,
12
+ "refund_status": null,
13
+ "error_code": null,
14
+ "error_description": null,
15
+ "udf": {},
16
+ "created_at": 1400826750
17
+ },
18
+ {
19
+ "id": "pay_19btGlBig6xZ2f",
20
+ "entity": "payment",
21
+ "amount": 500,
22
+ "currency": "INR",
23
+ "status": "created",
24
+ "amount_refunded": 0,
25
+ "refund_status": null,
26
+ "error_code": null,
27
+ "error_description": null,
28
+ "udf": {},
29
+ "created_at": 1400826750
30
+ }
31
+ ]
32
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "count": 1,
3
+ "entity": "collection",
4
+ "items": [
5
+ {
6
+ "id": "pay_29QQoUBi66xm2f",
7
+ "entity": "payment",
8
+ "amount": 500,
9
+ "currency": "INR",
10
+ "status": "created",
11
+ "amount_refunded": 0,
12
+ "refund_status": null,
13
+ "error_code": null,
14
+ "error_description": null,
15
+ "udf": {},
16
+ "created_at": 1400826750
17
+ }
18
+ ]
19
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "count": 2,
3
+ "entity": "collection",
4
+ "items": [
5
+ {
6
+ "id": "rfnd_AABBdHIieexn5c",
7
+ "entity": "refund",
8
+ "amount": 100,
9
+ "currency": "INR",
10
+ "payment_id": "fake_payment_id",
11
+ "created_at": 1500826750
12
+ },
13
+ {
14
+ "id": "rfnd_19btGlBig6xZ2f",
15
+ "entity": "refund",
16
+ "amount": 100,
17
+ "currency": "INR",
18
+ "payment_id": "fake_payment_id",
19
+ "created_at": 1500826750
20
+ }
21
+ ]
22
+ }
@@ -0,0 +1,24 @@
1
+ require 'test_helper'
2
+ require 'razorpay/entity'
3
+
4
+ module Razorpay
5
+ # Tests for Razorpay::Entity
6
+ class EntityTest < Minitest::Test
7
+ def setup
8
+ @hash = { 'a' => 1 }
9
+ @entity = Entity.new(@hash)
10
+ end
11
+
12
+ def test_attribute_get
13
+ assert_equal @hash['a'], @entity.a
14
+ end
15
+
16
+ def test_json_conversion
17
+ assert_equal '{"a":1}', @entity.to_json
18
+ end
19
+
20
+ def test_invalid_attribute_get
21
+ assert_raises(NameError, 'It must raise a NameError on invalid attribute') { @entity.b }
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,65 @@
1
+ require 'test_helper'
2
+ require 'razorpay/payment'
3
+ require 'razorpay/collection'
4
+
5
+ module Razorpay
6
+ # Tests for Razorpay::Payment
7
+ class RazorpayPaymentTest < Minitest::Test
8
+ def setup
9
+ @payment_id = 'fake_payment_id'
10
+
11
+ # Any request that ends with payments/payment_id
12
+ stub_get(/payments\/#{Regexp.quote(@payment_id)}$/, 'fake_payment')
13
+ stub_get(/payments$/, 'payment_collection')
14
+ end
15
+
16
+ def test_payment_should_be_defined
17
+ refute_nil Razorpay::Payment
18
+ end
19
+
20
+ def test_payments_should_be_available
21
+ payment = Razorpay::Payment.fetch(@payment_id)
22
+ assert_instance_of Razorpay::Payment, payment, 'Payment not an instance of Payment class'
23
+ assert_equal @payment_id, payment.id, 'Payment IDs do not match'
24
+ end
25
+
26
+ def test_all_payments
27
+ payments = Razorpay::Payment.all
28
+ assert_instance_of Razorpay::Collection, payments, 'Payments should be an array'
29
+ assert payments.items.size > 0, 'Payments should be more than one'
30
+ end
31
+
32
+ def test_all_payments_with_options
33
+ query = { 'count' => 1 }
34
+ stub_get(/payments\?count=1$/, 'payment_collection_with_one_payment')
35
+ payments = Razorpay::Payment.all(query)
36
+ assert_equal query['count'], payments.items.size, 'Payments array size should match'
37
+ end
38
+
39
+ def test_payment_refund
40
+ stub_post(%r{payments/#{@payment_id}/refund$}, 'fake_refund', {})
41
+ refund = Razorpay::Payment.fetch(@payment_id).refund
42
+ assert_instance_of Razorpay::Refund, refund
43
+ assert_equal refund.payment_id, @payment_id
44
+ end
45
+
46
+ def test_partial_refund
47
+ # For some reason, stub doesn't work if I pass it a hash of post body
48
+ stub_post(%r{payments/#{@payment_id}/refund$}, 'fake_refund', 'amount=2000')
49
+ refund = Razorpay::Payment.fetch(@payment_id).refund(amount: 2000)
50
+ assert_instance_of Razorpay::Refund, refund
51
+ assert_equal refund.payment_id, @payment_id
52
+ assert_equal refund.amount, 2000
53
+ end
54
+
55
+ def test_payment_capture
56
+ stub_post(%r{payments/#{@payment_id}/capture$}, 'fake_captured_payment', 'amount=5100')
57
+ payment = Razorpay::Payment.fetch(@payment_id)
58
+ assert_raises(ArgumentError, 'ArgumentError should be raised if amount is not provided') do
59
+ payment.capture
60
+ end
61
+ payment = payment.capture(amount: 5100)
62
+ assert_equal 'captured', payment.status
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,20 @@
1
+ require 'test_helper'
2
+ require 'razorpay'
3
+
4
+ module Razorpay
5
+ # Tests for Razorpay
6
+ class RazorpayTest < Minitest::Test
7
+ def setup
8
+ Razorpay.setup('key_id', 'key_secret')
9
+ end
10
+
11
+ def test_razorpay_should_be_defined
12
+ refute_nil Razorpay
13
+ end
14
+
15
+ def test_setup
16
+ auth = { username: 'key_id', password: 'key_secret' }
17
+ assert_equal auth, Razorpay.auth
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,31 @@
1
+ require 'test_helper'
2
+ require 'razorpay/payment'
3
+ require 'razorpay/refund'
4
+
5
+ module Razorpay
6
+ # Tests for Razorpay::Refund
7
+ class RazorpayRefundTest < Minitest::Test
8
+ def setup
9
+ @payment_id = 'fake_payment_id'
10
+ stub_get(/payments\/#{Regexp.quote(@payment_id)}$/, 'fake_payment')
11
+ end
12
+
13
+ def test_refund_should_be_defined
14
+ refute_nil Razorpay::Refund
15
+ end
16
+
17
+ def test_fetch_all_refunds
18
+ stub_get(%r{/payments/#{@payment_id}/refunds$}, 'refund_collection')
19
+ refunds = Razorpay::Payment.fetch(@payment_id).refunds.all
20
+ assert_instance_of Razorpay::Collection, refunds
21
+ end
22
+
23
+ def test_fetch_specific_refund
24
+ refund_id = 'fake_refund_id'
25
+ stub_get(%r{payments/#{@payment_id}/refunds/#{refund_id}$}, 'fake_refund')
26
+ refund = Razorpay::Payment.fetch(@payment_id).refunds.fetch('fake_refund_id')
27
+ assert_instance_of Razorpay::Refund, refund
28
+ assert_equal refund.id, refund_id
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,29 @@
1
+ require 'simplecov'
2
+ require 'minitest/autorun'
3
+ require 'webmock/minitest'
4
+
5
+ def fixture_file(filename)
6
+ return '' if filename == ''
7
+ file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename + '.json')
8
+ File.read(file_path)
9
+ end
10
+
11
+ def stub_response(_url, filename, status = nil)
12
+ response = { body: fixture_file(filename) }
13
+ response.merge!(status: status) unless status.nil?
14
+ response.merge!(headers: { 'Content-Type' => 'application/json' })
15
+ end
16
+
17
+ def stub_get(*args)
18
+ response = stub_response(*args)
19
+ url = args[0]
20
+ stub_request(:get, url).to_return(response)
21
+ end
22
+
23
+ def stub_post(*args)
24
+ # The last argument is post data
25
+ data = args.pop
26
+ response = stub_response(*args)
27
+ url = args[0]
28
+ stub_request(:post, url).with(body: data).to_return(response)
29
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: razorpay
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Abhay Rana
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '5.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '5.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.20'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.20'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '0.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '0.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: httparty
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '0.13'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '0.13'
97
+ description: Official ruby bindings for the Razorpay API
98
+ email:
99
+ - nemo@razorpay.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .editorconfig
105
+ - .gitignore
106
+ - .rubocop.yml
107
+ - .simplecov
108
+ - .travis.yml
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - lib/razorpay.rb
114
+ - lib/razorpay/collection.rb
115
+ - lib/razorpay/constants.rb
116
+ - lib/razorpay/entity.rb
117
+ - lib/razorpay/errors.rb
118
+ - lib/razorpay/errors/bad_request_error.rb
119
+ - lib/razorpay/errors/gateway_error.rb
120
+ - lib/razorpay/errors/razorpay_error.rb
121
+ - lib/razorpay/errors/server_error.rb
122
+ - lib/razorpay/payment.rb
123
+ - lib/razorpay/refund.rb
124
+ - lib/razorpay/request.rb
125
+ - razorpay-ruby.gemspec
126
+ - test/fixtures/fake_captured_payment.json
127
+ - test/fixtures/fake_payment.json
128
+ - test/fixtures/fake_refund.json
129
+ - test/fixtures/payment_collection.json
130
+ - test/fixtures/payment_collection_with_one_payment.json
131
+ - test/fixtures/refund_collection.json
132
+ - test/razorpay/test_entity.rb
133
+ - test/razorpay/test_payment.rb
134
+ - test/razorpay/test_razorpay.rb
135
+ - test/razorpay/test_refund.rb
136
+ - test/test_helper.rb
137
+ homepage: https://github.com/razorpay/razorpay-ruby
138
+ licenses:
139
+ - MIT
140
+ metadata: {}
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 2.4.1
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: Razorpay's Ruby API
161
+ test_files:
162
+ - test/fixtures/fake_captured_payment.json
163
+ - test/fixtures/fake_payment.json
164
+ - test/fixtures/fake_refund.json
165
+ - test/fixtures/payment_collection.json
166
+ - test/fixtures/payment_collection_with_one_payment.json
167
+ - test/fixtures/refund_collection.json
168
+ - test/razorpay/test_entity.rb
169
+ - test/razorpay/test_payment.rb
170
+ - test/razorpay/test_razorpay.rb
171
+ - test/razorpay/test_refund.rb
172
+ - test/test_helper.rb
173
+ has_rdoc: