WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
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
124 changes: 81 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,64 +1,102 @@
# Razorpay Go Client
# Razorpay Go SDK

Golang bindings for interacting with the Razorpay API
**Official Go bindings for the Razorpay API**

This is primarily meant for merchants who wish to perform interactions with the Razorpay API programatically
This SDK allows you to seamlessly integrate Razorpay APIs into your Go applications for managing payments, orders, customers, and more — programmatically.

Read up here for getting started and understanding the payment flow with Razorpay: <https://razorpay.com/docs/get-started/>
> 💡 **New to Razorpay?**
> Check out the [Getting Started Guide](https://razorpay.com/docs/get-started/) to understand payment flows and set up your account.

---

## Documentation

Documentation of Razorpay's API and their usage is available at <https://docs.razorpay.com>
For detailed API references and integration workflows, visit the [Razorpay API Documentation](https://razorpay.com/docs/api/).

---

## Requirements

- Go 1.18 or later

### Installation

```bash
go get github.com/razorpay/razorpay-go
```

## Usage
You need to setup your key and secret using the following:
You can find your API keys at <https://dashboard.razorpay.com/#/app/keys>.
**Initializing the Client**

The `NewClient` method creates a new instance of the Razorpay client, which is used to make API calls.

```go
import (
razorpay "github.com/razorpay/razorpay-go"
)

client := razorpay.NewClient("<YOUR_API_KEY>", "<YOUR_API_SECRET>")
```

- <YOUR_API_KEY>: Your Razorpay API Key ID.

- <YOUR_API_SECRET>: Your Razorpay API Key Secret.

You can find your API keys in the [Razorpay Dashboard](https://dashboard.razorpay.com/#/app/keys).

Once initialized, client provides access to different Razorpay resources like Orders, Payments, Customers, etc.

For example:

### Create an Order
```go
request := &resources.OrderRequest{
Amount: 1000,
Currency: "INR",
PartialPayment: true,
FirstPaymentMinAmount: 100,
Notes: resources.Notes{
"policy_name": "Jeevan Bima",
},
}

resp, err := client.Order.Create(request, nil)

if err != nil {
fmt.Printf("Error creating order: %v\n", err)
return
}
fmt.Printf("Create order Response:\n%s\n", resp.ID)
```

### Update an Order
```go
request := &resources.OrderUpdateRequest{
Notes: resources.Notes{
"policy_name": "Jeevan Bima",
},
}
resp, err := client.Order.Update("order_QOSJNLwLsRK0bB", request, nil)

if err != nil {
fmt.Printf("Error updating order: %v\n", err)
return
}
fmt.Printf("Updating order Response:\n%s\n", resp.ID)
```

### Fetch an Order
```go
response, err := client.Order.Fetch("order_QOSJNLwLsRK0bB", nil, nil)

if err != nil {
fmt.Printf("Error fetching order: %v\n", err)
return
}
fmt.Printf("Fetching order Response:\n%s\n", response.ID)
```

Note: All methods below return a `map[string]interface{}` and `error`. All methods accept an `extraHeaders` param of type `map[string]string`, allowing you to optinally set extra HTTP headers on the request.

## Supported Resources

- [Account](documents/account.md)
- [Customer](documents/customers.md)
- [Token](documents/token.md)
- [Order](documents/order.md)
- [Payments](documents/payment.md)
- [Product Configuration](documents/productConfiguration.md)
- [Settlements](documents/settlement.md)
- [Stakeholder](documents/stakeholder.md)
- [Fund](documents/fundAccount.md)
- [Refunds](documents/refund.md)
- [Invoice](documents/invoice.md)
- [Item](documents/item.md)
- [Plan](documents/plan.md)
- [PaymentVerfication](documents/paymentVerification.md)
- [Subscriptions](documents/subscription.md)
- [Add-on](documents/addon.md)
- [Payment Links](documents/paymentLink.md)
- [Smart Collect](documents/virtualAccount.md)
- [Route](documents/transfer.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)
- [Token](documents/token.md)
- [Webhook](documents/webhook.md)
- [Document](documents/document.md)
- [Dispute](documents/dispute.md)
- [Iin](documents/iin.md)

## License

The Razorpay Go SDK is released under the MIT License. See [LICENSE](LICENSE) file for more details.
The Razorpay Go SDK is released under the MIT License. See [LICENSE](LICENSE) file for more details.
6 changes: 3 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"net/http"
"time"

"github.com/razorpay/razorpay-go/constants"
"github.com/razorpay/razorpay-go/requests"
"github.com/razorpay/razorpay-go/resources"
"github.com/razorpay/razorpay-go/v2/constants"
"github.com/razorpay/razorpay-go/v2/requests"
"github.com/razorpay/razorpay-go/v2/resources"
)

//Request ...
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/razorpay/razorpay-go
module github.com/razorpay/razorpay-go/v2

go 1.14

Expand Down
49 changes: 47 additions & 2 deletions requests/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"path/filepath"
"time"

"github.com/razorpay/razorpay-go/constants"
"github.com/razorpay/razorpay-go/errors"
"github.com/razorpay/razorpay-go/v2/constants"
"github.com/razorpay/razorpay-go/v2/errors"
)

//Auth holds the values required to authenticate the requests made to Razorpay APIs
Expand Down Expand Up @@ -275,3 +275,48 @@ func (request *Request) File(path string, params FileUploadParams, extraHeaders

return request.doRequestResponse(req)
}

// Call makes an HTTP request to the Razorpay API
func (request *Request) Call(method, path string, payload interface{}, result interface{}, extraHeaders map[string]string) error {
var jsonStr []byte
var err error

// Handle different types of payload
switch p := payload.(type) {
case map[string]interface{}:
// If it's already a map, use it directly
jsonStr, err = json.Marshal(p)
case nil:
// If payload is nil, use empty map
jsonStr, err = json.Marshal(map[string]interface{}{})
default:
// For any other type (struct), convert to map first
jsonStr, err = json.Marshal(p)
}

if err != nil {
return err
}

url := fmt.Sprintf("%s%s", request.BaseURL, path)
req, err := http.NewRequest(method, url, bytes.NewBuffer(jsonStr))
if err != nil {
return err
}

req.SetBasicAuth(request.Auth.Key, request.Auth.Secret)
request.addRequestHeaders(req, extraHeaders)

resp, err := request.doRequestResponse(req)
if err != nil {
return err
}

// Convert response to result struct
jsonData, err := json.Marshal(resp)
if err != nil {
return err
}

return json.Unmarshal(jsonData, result)
}
Loading
Loading