api - Razorpay 集成错误(调用 client.Order.Create 时参数不足)
问题描述
尝试实现,基于razorpay网站 代码中的官方文档:
11 func indexpageGet(c *gin.Context) {
12
13 client := razorpay.NewClient("rzp_test_zlsYshjhjhjln", "9LtUy4qhghghgh2asp59es")
14
15 data := map[string]interface{}{
16 "amount": 1234,
17 "currency": "INR",
18 "receipt_id": "some_receipt_id",
19 }
20 body, err := client.Order.Create(data)
21 if err != nil {
22 fmt.Println(err)
23 }
24
25 fmt.Println(body)
编译错误:
./main.go:20:34: not enough arguments in call to client.Order.Create
have (map[string]interface {})
want (map[string]interface {}, map[string]string)
我的观察:函数client.Order.Create(data)
需要两个参数我从 razorpay 库中确认了它(参见函数定义部分)。所以解决方案是我也需要传递第二个参数(extraHeaders
)。
// Create creates a new order for the given data
func (order *Order) Create(data map[string]interface{}, extraHeaders map[string]string) (map[string]interface{}, error) {
return order.Request.Post(constants.ORDER_URL, data, extraHeaders)
}
我被卡住的一点是什么是extraHeaders
我需要传递的价值?
解决方案
根据问题中的评论,做了两件事使它起作用:(请参阅下面代码中的评论)
11 func indexpageGet(c *gin.Context) {
12
13 client := razorpay.NewClient("rzp_test_zlsYsrvuUxxhln", "9LtUy4qpLCOtl4Gz2asp59es")
14
15 data := map[string]interface{}{
16 "amount": 1234,
17 "currency": "INR",
18 "receipt": "110",
19 //"receipt_id": "some_receipt_id", // 1st Mistake in documentation it should be 'receipt', corrected in above line
20 }
21
22 extraHeader := make(map[string]string) // 2nd Mistake in documentation , corrected by creating an empty map and passed as the second argument in below function.
23 body, err := client.Order.Create(data,extraHeader)
24 if err != nil {
25 fmt.Println(err)
26 }
27
28 fmt.Println(body)
推荐阅读
- performance - 每次使用 docker-compose 时,yarn install 链接依赖项都很慢
- scala - Spark 2.4.3 - Scala 2.12.3 - 对象 apache 不是包 org 的成员
- android - 仅在深色模式下自定义应用栏颜色
- flutter - Flutter - InkWell 在更改“onTap”方法时不起作用
- hive - 如何在配置单元中转换 ddmonyyyy 日期格式
- android - 在通知生成器中使用 setProgress 不适用于媒体样式通知
- javascript - express 错误 [ERR_HTTP_HEADERS_SENT]: 发送到客户端后无法设置标头
- node.js - 使用 Proximo 时连接到 ClearDB 时出错
- mysql - 如何计算每个类别的作业的唯一点击次数
- android - Android Studio:如何向使用自签名证书的 Node.js 服务器发送 HTTPS 请求?