-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsimple_get_payment_link.go
More file actions
81 lines (61 loc) · 1.7 KB
/
simple_get_payment_link.go
File metadata and controls
81 lines (61 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import(
"fmt"
"github.com/yourpayments/go-api-client"
"github.com/google/uuid"
)
func main(){
merchant := ypmn.GetMerchantFromEnv() // Получить данные мерчанта из environment
// merchant := ypmn.Merchant{MerchantCode:"CC1", MerchantSecret:"SECRET_KEY"}
// Можно передать данные вручную
merchantPaymentReference := fmt.Sprintf("%s",uuid.New())
product := ypmn.Product{
Name:"Заказ № " + merchantPaymentReference,
SKU: merchantPaymentReference,
UnitPrice: 200.42,
Quantity: 1,
}
billing := ypmn.Billing{
CountryCode:"RU",
FirstName:"Иван",
LastName:"Петров",
Email:"test1@ypmn.ru",
Phone:"+7-800-555-35-35",
City:"Москва",
}
client := ypmn.Client{
Billing: billing,
}
authorization := ypmn.Authorization{
PaymentMethod: ypmn.CCVISAMC,
UsePaymentPage: "YES",
}
payment := ypmn.Payment{
Currency:"RUB",
MerchantPaymentReference: merchantPaymentReference,
ReturnUrl:"https://example.com/return",
Сlient: client,
Authorization: authorization,
}
payment.AddProduct(product)
apiRequest := ypmn.ApiRequest{
Merchant: merchant,
SandboxModeIsOn: true,
DebugModeIsOn: true,
}
responce, err := apiRequest.SendAuthRequest(payment)
if(err != nil){
panic("Error: " + err.Error())
}
code, _ := responce["code"].(float64)
if(int(code) == 429){
panic("Слишком много запросов")
}
if(int(code) != 200){
fmt.Println(responce)
panic("Bad responce")
}
paymentResult, _ := responce["paymentResult"].(map[string]interface{})
link, _ := paymentResult["url"].(string)
fmt.Println("Перейдите по ссылке, чтобы оплатить: " + link)
}