├── .env
├── .gitignore
├── .travis.yml
├── LICENSE
├── README.MD
├── payU.png
└── payu.go
/.env:
--------------------------------------------------------------------------------
1 | #PayU Payment sandbox details
2 | merchant_key_stage = "XXXXXXXXX"
3 | merchant_salt_stage = "XXXXXXX"
4 | redirect_url_stage = `https://test.payu.in/_payment`
5 |
6 | #PayU Payment Production details
7 | merchant_key = "XXXXXXXXX"
8 | merchant_salt = "XXXXXXXX"
9 | redirect_url = `https://secure.payu.in/_payment`
10 |
11 |
12 | PAYMENT_MIDDLEWARE_URL = `http://localhost/payu.php`
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: go
2 |
3 | go:
4 | - "1.12"
5 |
6 | os:
7 | - linux
8 |
9 | dist: trusty
10 | sudo: false
11 | install: true
12 |
13 | script:
14 | - unset GOPATH
15 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 MindInventory
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.MD:
--------------------------------------------------------------------------------
1 | # Quick PayU Integration using Golang
2 |
3 |
4 |
5 |
6 | [](https://github.com/mindinventory/Golang-PayU/blob/master/LICENSE)
7 |
8 | PayU is one of the widely accepted payment gateways for online payment integration especially in India and other countries like Poland, Brazil, SouthAfrica and Turkey. It might be interesting for you if you are having your website made in GoLang and looking for integrating Payu it as it might be even more simple for you with this repository.
9 |
10 |
11 |
12 | ## What it is?
13 |
14 | It is a well managed repository, using which one can integrate PayU in their GoLang Website in quick simple steps once they get PayU Merchant Key from PayU official website.
15 |
16 | ## Prerequisite
17 |
18 | 1. Create a merchant account in PayU.
19 | 2. Get PAYU_MERCHANT_KEY which will be get once the onboarding process is completed.
20 |
21 | ## Steps to Follow
22 |
23 | 1. Set Up Merchant Key got from above process
24 |
25 | Provide the value for PAYU_MERCHANT_KEY in .env file
26 |
27 | ```
28 | #PayU Payment sandbox details
29 | merchant_key_stage = "XXXXXXXXX"
30 | merchant_salt_stage = "XXXXXXX"
31 | redirect_url_stage = `https://test.payu.in/_payment`
32 |
33 | #PayU Payment Production details
34 | merchant_key = "XXXXXXXXX"
35 | merchant_salt = "XXXXXXXX"
36 | redirect_url = `https://secure.payu.in/_payment`
37 |
38 | PAYMENT_MIDDLEWARE_URL = `http://localhost/payu.php`
39 |
40 | ```
41 |
42 | 2. Verify Checksum Hash for successful transactions.
43 |
44 | A checksum hash is generated by the payu which is verified on merchant server for successful transaction. For this there is a file payu.go which need to be copied to your local as it works for generation and verification of checksum.
45 |
46 | 3. Set Mode
47 |
48 | PayU integration can be done in two stages i.e. staging and production modes have different PayU transaction urls.
49 |
50 | 1. In staging mode we are using sandbox details for testing the payU working
51 |
52 | ```
53 | Staging mode transaction url
54 | https://test.payu.in/_payment
55 | ```
56 |
57 | 2. If you are using production mode means it accepts original details of payU
58 |
59 | ```
60 | Production mode transaction url
61 | https://secure.payu.in/_payment
62 | ```
63 |
64 | ## LICENSE!
65 |
66 | PayU integration using Golang is [MIT-licensed](https://github.com/mindinventory/Golang-PayU/blob/master/LICENSE)
67 |
68 | ## Let us know!
69 | We’d be really happy if you sent us links to your projects where you use our component. Just send an email to sales@mindinventory.com And do let us know if you have any questions or suggestion regarding our work.
70 |
71 |
--------------------------------------------------------------------------------
/payU.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mindinventory/Golang-PayU/3bc1b07e73988fad6bb60954cf0eea9bb86b3835/payU.png
--------------------------------------------------------------------------------
/payu.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "crypto/sha512"
5 | "encoding/json"
6 | "fmt"
7 | "net/http"
8 | "os"
9 | )
10 |
11 | type PayUMoneyOrderResponse struct {
12 | Amount string `json:"amount"`
13 | Txnid string `json:"txnid"`
14 | Key string `json:"key"`
15 | ProductInfo string `json:"productinfo"`
16 | FirstName string `json:"firstname"`
17 | Email string `json:"email"`
18 | Hash string `json:"hash"`
19 | Surl string `json:"surl"`
20 | Phone string `json:"phone"`
21 | ServiceProvider string `json:"service_provider"`
22 | Furl string `json:"furl"`
23 | Udf1 string `json:"udf1"`
24 | EnforcePaymethod string `json:"enforce_paymethod"`
25 | }
26 |
27 | func Message(status int, message string) map[string]interface{} {
28 | return map[string]interface{}{"status": status, "message": message}
29 | }
30 |
31 | func Respond(w http.ResponseWriter, data map[string]interface{}) {
32 | w.Header().Add("Content-Type", "application/json")
33 | json.NewEncoder(w).Encode(data)
34 | }
35 |
36 | func main() {
37 |
38 | var MERCHANT_KEY = os.Getenv("merchant_key")
39 | var SALT = os.Getenv("merchant_salt")
40 | var txnid = "6647747839544"
41 | var name = "UserName"
42 | var email = "xyz@gmail.com"
43 | var amount = "10.00"
44 | var phone = "0000000000"
45 | var surl = os.Getenv("PAYMENT_MIDDLEWARE_URL")
46 | var furl = os.Getenv("PAYMENT_MIDDLEWARE_URL")
47 | var enforcePaymethod = "creditcard"
48 | var productInfo = "PAYU"
49 | var orderId = "2010342311"
50 |
51 | var hashString = MERCHANT_KEY + "|" + txnid + "|" + amount + "|" + productInfo + "|" + name + "|" + email + "|" + orderId + "||||||||||" + SALT
52 | sha_512 := sha512.New()
53 | sha_512.Write([]byte(hashString))
54 | var final_key = fmt.Sprintf("%x", sha_512.Sum(nil))
55 |
56 | orderResponse := payUOrderResponseFun(amount, txnid, MERCHANT_KEY, productInfo, name, email, final_key, surl, phone, "", furl, enforcePaymethod, orderId)
57 | var setResponse = map[string]interface{}{}
58 | response := Message(0, "Order place successfully.")
59 | setResponse["request_data"] = orderResponse
60 | setResponse["redirect_url"] = os.Getenv("redirect_url")
61 | setResponse["callback_url"] = os.Getenv("PAYMENT_MIDDLEWARE_URL") //Get response to this URL
62 | response["data"] = setResponse
63 |
64 | fmt.Println("response", response)
65 | }
66 |
67 | func payUOrderResponseFun(amountString string, txnid string, merchantKey string, productInfo string, name string, email string, final_key string, surl string, phone string, serviceProvider string, furl string, enforcePaymethod string, orderId string) PayUMoneyOrderResponse {
68 | res := PayUMoneyOrderResponse{
69 | Amount: amountString,
70 | Txnid: txnid,
71 | Key: merchantKey,
72 | ProductInfo: productInfo,
73 | FirstName: name,
74 | Email: email,
75 | Hash: final_key,
76 | Surl: surl,
77 | Phone: phone,
78 | ServiceProvider: serviceProvider,
79 | Furl: furl,
80 | EnforcePaymethod: enforcePaymethod,
81 | Udf1: orderId,
82 | }
83 | return res
84 | }
85 |
--------------------------------------------------------------------------------