Skip to content

Commit 5ddb8a5

Browse files
committed
fix segfault and add ask for shipping
1 parent d4d1a46 commit 5ddb8a5

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

.DS_Store

6 KB
Binary file not shown.

menu/createNewLink.go

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func CreateNewLink() {
2323
return
2424
}
2525
stripe.Key = settings.ApiKey
26+
params := new(stripe.PaymentLinkParams)
2627

2728
prompt := promptui.Prompt{
2829
Label: "Set Payment Link Nickname",
@@ -47,18 +48,34 @@ func CreateNewLink() {
4748
println("Error: %v\n", err)
4849
return
4950
}
50-
var allowCouponBool bool
5151
if allowCoupon == "y" {
52-
allowCouponBool = true
52+
params.AllowPromotionCodes = stripe.Bool(true)
5353
} else {
54-
allowCouponBool = false
54+
params.AllowPromotionCodes = stripe.Bool(false)
55+
}
56+
57+
prompt = promptui.Prompt{
58+
Label: "Ask for shipping address? (y/n)",
59+
}
60+
shippingAddress, _ := prompt.Run()
61+
if err != nil {
62+
println("Error: %v\n", err)
63+
return
64+
}
65+
if shippingAddress == "y" {
66+
params.ShippingAddressCollection = &stripe.PaymentLinkShippingAddressCollectionParams{
67+
AllowedCountries: stripe.StringSlice([]string{
68+
"AC", "AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AQ", "AR", "AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CV", "CW", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY", "HK", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MK", "ML", "MM", "MN", "MO", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", "SX", "SZ", "TA", "TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VN", "VU", "WF", "WS", "XK", "YE", "YT", "ZA", "ZM", "ZW", "ZZ",
69+
}),
70+
}
5571
}
5672

5773
items := []*stripe.PaymentLinkLineItemParams{}
5874

5975
for {
76+
fmt.Println("Product ID, qty and Price in cents (e.g. $1.99 = 199), separated by space.")
6077
prompt := promptui.Prompt{
61-
Label: "Product ID, qty and Price in cents (e.g. $1.99 = 199), separated by space. Leave blank to finish.",
78+
Label: "Add Line Item or leave blank to finish",
6279
}
6380
input, err := prompt.Run()
6481
if err != nil {
@@ -197,15 +214,12 @@ func CreateNewLink() {
197214
}
198215
selectedCustomFields = append(selectedCustomFields, allCustomFields[index].ToStripe())
199216
}
217+
218+
params.CustomFields = selectedCustomFields
200219
}
201220

202221
// Stripe hates empty custom fields
203-
var params *stripe.PaymentLinkParams
204222
params.LineItems = items
205-
params.AllowPromotionCodes = stripe.Bool(allowCouponBool)
206-
if len(selectedCustomFields) != 0 {
207-
params.CustomFields = selectedCustomFields
208-
}
209223
paymentConfirmation := DB.GetSettings().PaymentConfirmationMessage
210224
if paymentConfirmation != "" {
211225
params.AfterCompletion = &stripe.PaymentLinkAfterCompletionParams{

0 commit comments

Comments
 (0)