-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #128 from razorpay/addon_update
addon update with test case
- Loading branch information
Showing
111 changed files
with
12,987 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# This workflow uses actions that are not certified by GitHub. | ||
# They are provided by a third-party and are governed by | ||
# separate terms of service, privacy policy, and support | ||
# documentation. | ||
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake | ||
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby | ||
|
||
name: Ruby | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
test: | ||
|
||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
ruby-version: ['2.6', '2.7', '3.0'] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Ruby | ||
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby, | ||
# change this to (see https://github.com/ruby/setup-ruby#versioning): | ||
# uses: ruby/setup-ruby@v1 | ||
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e | ||
with: | ||
ruby-version: ${{ matrix.ruby-version }} | ||
bundler-cache: true # runs 'bundle install' and caches installed gems automatically | ||
- name: Run tests | ||
run: bundle exec rake |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Razorpay Ruby bindings | ||
|
||
[![Build Status](https://travis-ci.org/razorpay/razorpay-ruby.svg?branch=master)](https://travis-ci.org/razorpay/razorpay-ruby) [![Gem Version](https://badge.fury.io/rb/razorpay.svg)](http://badge.fury.io/rb/razorpay) [![Coverage Status](https://coveralls.io/repos/github/Razorpay/razorpay-ruby/badge.svg?branch=master)](https://coveralls.io/github/Razorpay/razorpay-ruby?branch=master) [![License](http://img.shields.io/:license-mit-blue.svg)](http://doge.mit-license.org) | ||
[![Build Status](https://travis-ci.org/razorpay/razorpay-ruby.svg?branch=master)](https://travis-ci.org/razorpay/razorpay-ruby) [![Gem Version](https://img.shields.io/badge/gem%20version-v3.0.0-dark%20green.svg)](http://badge.fury.io/rb/razorpay) [![Coverage Status](https://coveralls.io/repos/github/Razorpay/razorpay-ruby/badge.svg?branch=master)](https://coveralls.io/github/Razorpay/razorpay-ruby?branch=master) [![License](http://img.shields.io/:license-mit-blue.svg)](http://doge.mit-license.org) | ||
|
||
This is the base ruby gem for interacting with the Razorpay API. This is primarily meant for users who wish to perform interactions with the Razorpay API programatically. | ||
|
||
|
@@ -20,6 +20,9 @@ Or install it yourself as: | |
|
||
$ gem install razorpay | ||
|
||
## Requirements | ||
|
||
Ruby 2.6.8 or later | ||
## Usage | ||
|
||
Remember to `require 'razorpay'` before anything else. | ||
|
@@ -39,131 +42,30 @@ You can find your API keys at <https://dashboard.razorpay.com/#/app/keys>. | |
|
||
If you are using rails, the right place to do this might be `config/initializers/razorpay.rb`. | ||
|
||
The most common construct is capturing a payment, which you do via the following: | ||
|
||
```rb | ||
Razorpay::Payment.fetch("payment_id").capture({amount:500}) | ||
# Note that the amount should come from your session, so as to verify | ||
# that the purchase was correctly done and not tampered | ||
``` | ||
|
||
You can refund a payment via the following: | ||
|
||
```rb | ||
Razorpay::Payment.fetch("payment_id").refund({amount:500}) | ||
refunds = Razorpay::Payment.fetch("payment_id").refunds | ||
``` | ||
|
||
A payment can also be refunded without fetching it: | ||
```rb | ||
refund = Razorpay::Refund.create(payment_id:"payment_id") | ||
Razorpay::Refund.fetch(refund.id) | ||
``` | ||
|
||
If payment is captured or refunded via `capture!` or `refund!`, then the calling object is also updated: | ||
```rb | ||
payment = Razorpay::Payment.fetch('payment_id') | ||
payment.status | ||
# 'authorized' | ||
payment.capture! | ||
payment.status | ||
# 'captured' | ||
payment.refund! | ||
payment.status | ||
# 'refunded' | ||
``` | ||
|
||
For other applications (such as fetching payments and refunds), | ||
see our online documentation on <https://docs.razorpay.com> | ||
|
||
### Orders API | ||
|
||
You can use the orders API using the following constructs: | ||
|
||
You can find docs at <https://docs.razorpay.com/v1/page/orders> | ||
|
||
```rb | ||
order = Razorpay::Order.create amount: 5000, currency: 'INR', receipt: 'TEST' | ||
# order.id = order_50sX9hGHZJvjjI | ||
|
||
# Same collection as Refunds or Payments | ||
orders = Razorpay::Order.all | ||
|
||
# Fetching an Order | ||
order = Razorpay::Order.fetch('order_50sX9hGHZJvjjI') | ||
puts order.amount | ||
|
||
# Fetching payments corresponding to an order | ||
payments = order.payments | ||
``` | ||
|
||
### Verification | ||
You can use the Utility class to verify the signature received in response to a payment made using Orders API | ||
```rb | ||
puts payment_response | ||
# { | ||
# :razorpay_order_id => "fake_order_id", | ||
# :razorpay_payment_id => "fake_payment_id", | ||
# :razorpay_signature => "signature" | ||
# } | ||
Razorpay::Utility.verify_payment_signature(payment_response) | ||
``` | ||
You can also [verify the signature](https://github.com/razorpay/razorpay-ruby/wiki/Webhooks) received in a webhook: | ||
```rb | ||
Razorpay::Utility.verify_webhook_signature(webhook_body, webhook_signature, webhook_secret) | ||
``` | ||
|
||
### Customers | ||
```rb | ||
# Create a customer | ||
customer = Razorpay::Customer.create email: '[email protected]', contact: '9876543210' | ||
puts customer.id #cust_6vRXClWqnLhV14 | ||
``` | ||
|
||
### Cards | ||
```rb | ||
# Fetch a card | ||
card = Razorpay::Card.fetch('card_7EZLhWkDt05n7V') | ||
puts card.network #VISA | ||
``` | ||
|
||
You can find cards API documentation at <https://docs.razorpay.com/v1/page/cards>. | ||
|
||
### Invoices | ||
```rb | ||
# Creating an invoice | ||
invoice = Razorpay::Invoice.create customer_id: customer.id, amount: 100, currency: 'INR', description: 'Test description', type: 'link' | ||
``` | ||
|
||
You can find invoices API documentation at <https://docs.razorpay.com/v1/page/invoices>. | ||
|
||
### Plan | ||
```rb | ||
# Creating a plan | ||
plan = Razorpay::Plan.create interval: 1, period: 'monthly', item: { name: 'fake_plan', description: 'fake_desc', currency: 'INR', amount: 500 }, notes: { identifier: 'plan_monthly_super' } | ||
``` | ||
|
||
You can find plan API documentation at <https://razorpay.com/docs/subscriptions/api/#plan>. | ||
|
||
### Subscription | ||
```rb | ||
# Creating a subscription and starting after 24 hours (24 hours = 60 * 60 * 24) | ||
subscription = Razorpay::Subscription.create plan_id: plan.id, customer_id: customer.id, start_at: (Time.now + (60 * 60 * 24)).to_i, total_count: 3 | ||
``` | ||
|
||
You can find subscription API documentation at <https://razorpay.com/docs/subscriptions/api/#subscription>. | ||
|
||
### Addon | ||
```rb | ||
# Creating an addon | ||
subscription_addon = Razorpay::Addon.create subscription.id, item: { name: 'fake_plan', description: 'fake_desc', currency: 'INR', amount: 500 }, quantity: 1 | ||
|
||
# Fetching an addon | ||
addon = Razorpay::Addon.fetch subscription_addon.id | ||
``` | ||
|
||
You can find addon API documentation at <https://razorpay.com/docs/subscriptions/api/#add-on>. | ||
|
||
## Supported Resources | ||
- [Customer](documents/customer.md) | ||
- [Token](documents/tokens.md) | ||
- [Order](documents/order.md) | ||
- [Payments](documents/payment.md) | ||
- [Settlements](documents/settlement.md) | ||
- [Fund](documents/fund.md) | ||
- [Refunds](documents/refund.md) | ||
- [Invoice](documents/Invoice.md) | ||
- [Plan](documents/plan.md) | ||
- [Item](documents/items.md) | ||
- [Subscriptions](documents/subscriptions.md) | ||
- [Add-on](documents/addon.md) | ||
- [Payment Links](documents/paymentLink.md) | ||
- [Smart Collect](documents/virtualAccount.md) | ||
- [Transfer](documents/transfers.md) | ||
- [QR Code](documents/qrcode.md) | ||
- [Emandate](documents/emandate.md) | ||
- [Cards](documents/card.md) | ||
- [Paper NACH](documents/papernach.md) | ||
- [UPI](documents/upi.md) | ||
- [Register Emandate and Charge First Payment Together](documents/registerEmandate.md) | ||
- [Register NACH and Charge First Payment Together](documents/registerNach.md) | ||
- [Payment Verification](documents/paymentVerification.md) | ||
## Development | ||
|
||
- Everything is namespaced under the Razorpay module | ||
|
@@ -183,19 +85,6 @@ You can find addon API documentation at <https://razorpay.com/docs/subscriptions | |
5. Push to the branch (`git push origin my-new-feature`) | ||
6. Create a new Pull Request | ||
|
||
## Supported Versions | ||
|
||
While we support [all currently supported versions of Ruby](https://www.ruby-lang.org/en/downloads/branches/) | ||
only, the code is tested against the following versions: | ||
|
||
* 1.9.3 | ||
* 2.0.0 | ||
* 2.1.10 | ||
* 2.3.8 | ||
* 2.4.6 | ||
* 2.5.5 | ||
* 2.6.2 | ||
|
||
## Release | ||
|
||
Steps to follow for a release: | ||
|
Oops, something went wrong.