package razorpay import ( "cf-capital/module_server/handlers/slack" "github.com/razorpay/razorpay-go/utils" log "github.com/rs/zerolog/log" "time" razorpay "github.com/razorpay/razorpay-go" ) type Payment struct { Amount float64 ReceiptId string Notes1 string Notes2 string Description string AccountId int64 TransactionId string Customer Customer Plan Plan } type Plan struct { Name string } type Customer struct { Name string Contact string Email string } func (manager Payment) GetLink() (interface{}, error) { log.Print("calling GetLink") client := razorpay.NewClient("rzp_live_C1EbEhewTx7t5w", "O2KsmTzLWrtfVc309gMTd9br") //client := razorpay.NewClient("rzp_test_hnn4Ksgmvr8ko0", "mneb7p7QcDPlxMlMfimCTi79") expire_by := time.Now().AddDate(0, 0, 1).UnixNano() / int64(time.Millisecond) log.Print(expire_by) data := map[string]interface{}{ "amount": manager.Amount, "currency": "INR", "accept_partial": false, "first_min_partial_amount": 0, "expire_by": expire_by, "reference_id": manager.ReceiptId, "description": manager.Description, "customer": map[string]interface{}{ "name": manager.Customer.Name, "contact": manager.Customer.Contact, "email": manager.Customer.Email, }, "notify": map[string]interface{}{ "sms": true, "email": true, }, "reminder_enable": false, "notes": map[string]interface{}{ "investment_plan": manager.Plan.Name, "account_id": manager.AccountId, "transaction_id": manager.TransactionId, }, "callback_url": "https://app.creditfaircapital.in/investment/payment-confirmation", //"callback_url": "http://localhost:5001/v0/payment/payment-confirmation", "callback_method": "get", } log.Print(data) log.Print("calling razorpay payment link create") body, err := client.PaymentLink.Create(data, nil) if err != nil { log.Print("GetLink error") log.Print(err.Error()) return nil, err } log.Print("body") log.Print(body) return body, nil } func Verify(params map[string]interface{}) bool { secret := "mneb7p7QcDPlxMlMfimCTi79" status := utils.VerifyPaymentLinkSignature(params, params["signature"].(string), secret) if status || params["payment_link_status"] == "paid" { log.Print("Verified") params := map[string]interface{}{ "payment_link_id": params["payment_link_id"], "razorpay_payment_id": params["razorpay_payment_id"], "payment_link_reference_id": params["payment_link_reference_id"], "payment_link_status": params["payment_link_status"], } slack.SendSlack("Payment Verification - Success", params) log.Print("Payment verified") } else { params := map[string]interface{}{ "payment_link_id": params["payment_link_id"], "razorpay_payment_id": params["razorpay_payment_id"], "payment_link_reference_id": params["payment_link_reference_id"], "payment_link_status": params["payment_link_status"], } slack.SendSlack("Payment Verification - Failure", params) log.Print("Verification failed") } return true }