Skip to content

Commit 380ae81

Browse files
first commit
0 parents  commit 380ae81

11 files changed

Lines changed: 4370 additions & 0 deletions

File tree

function.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package function_extension_template
2+
3+
// #include <stdlib.h>
4+
import "C"
5+
6+
import (
7+
"unsafe"
8+
)
9+
10+
func PtrToString(ptr uint32, size uint32) string {
11+
return unsafe.String((*byte)(unsafe.Pointer(uintptr(ptr))), size)
12+
}
13+
14+
func StringToLeakedPtr(s string) (uint32, uint32) {
15+
size := C.ulong(len(s))
16+
ptr := unsafe.Pointer(C.malloc(size))
17+
copy(unsafe.Slice((*byte)(ptr), size), s)
18+
return uint32(uintptr(ptr)), uint32(size)
19+
}

go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module github.com/shoplinedev/function-extensions-template
2+
3+
go 1.20
4+

log.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package function_extension_template
2+
3+
// #include <stdlib.h>
4+
import "C"
5+
6+
import (
7+
"runtime"
8+
"unsafe"
9+
)
10+
11+
// Log a message to the console using _Log.
12+
func Log(message string) {
13+
ptr, size := StringToPtr(message)
14+
_Log(ptr, size)
15+
runtime.KeepAlive(message) // keep message alive until ptr is no longer needed.
16+
}
17+
18+
//export _Log
19+
func _Log(ptr, size uint32)
20+
21+
func StringToPtr(s string) (uint32, uint32) {
22+
ptr := unsafe.Pointer(unsafe.StringData(s))
23+
return uint32(uintptr(ptr)), uint32(len(s))
24+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module github.com/shoplinedev/function-extensions-template/templates/payment-customizations
2+
3+
go 1.20
4+
5+
require (
6+
github.com/mailru/easyjson v0.7.7
7+
github.com/shoplinedev/function-extensions-template v1.0.1
8+
)
9+
10+
require github.com/josharian/intern v1.0.0 // indirect
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
query Input {
2+
checkout {
3+
cost {
4+
totalAmount {
5+
amount
6+
}
7+
}
8+
}
9+
paymentCustomizations {
10+
metafield(namespace: "payment-customization", key: "function-configuration") {
11+
value, type
12+
}
13+
}
14+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"github.com/mailru/easyjson"
6+
function "github.com/shoplinedev/function-extensions-template"
7+
"github.com/shoplinedev/function-extensions-template/templates/payment-customizations/module"
8+
)
9+
10+
func PaymentCustomizationFunction(req *module.PaymentCustomizationFunctionRequest) (result module.PaymentCustomizationFunctionResponse) {
11+
return module.PaymentCustomizationFunctionResponse{}
12+
}
13+
14+
var _ = fmt.Printf
15+
var _ = function.Log
16+
var _ = easyjson.Marshal
Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
package module
2+
3+
type PaymentCustomizationFunctionRequest struct {
4+
Checkout *Checkout `json:"checkout"`
5+
Localization *Localization `json:"localization"`
6+
PaymentCustomizations []*PaymentCustomization `json:"paymentCustomizations"`
7+
PresentmentCurrencyRate *ExchangeRate `json:"presentmentCurrencyRate"`
8+
}
9+
10+
type Operation struct {
11+
Hide *HideOperation `json:"hide"`
12+
Move *MoveOperation `json:"move"`
13+
Rename *RenameOperation `json:"rename"`
14+
}
15+
16+
//easyjson:json
17+
type PaymentCustomizationFunctionResponses []PaymentCustomizationFunctionResponse
18+
19+
type PaymentCustomizationFunctionResponse struct {
20+
Operations []Operation `json:"operations"`
21+
}
22+
23+
type HideOperation struct {
24+
PaymentMethodId *string `json:"paymentMethodId"`
25+
}
26+
27+
type MoveOperation struct {
28+
Index *int64 `json:"index"`
29+
PaymentMethodId *string `json:"paymentMethodId"`
30+
}
31+
32+
type RenameOperation struct {
33+
Name *string `json:"name"`
34+
PaymentMethodId *string `json:"paymentMethodId"`
35+
}
36+
37+
type Enum__TypeKind string
38+
39+
const Enum__TypeKindSCALAR Enum__TypeKind = "SCALAR"
40+
const Enum__TypeKindOBJECT Enum__TypeKind = "OBJECT"
41+
const Enum__TypeKindINTERFACE Enum__TypeKind = "INTERFACE"
42+
const Enum__TypeKindUNION Enum__TypeKind = "UNION"
43+
const Enum__TypeKindENUM Enum__TypeKind = "ENUM"
44+
const Enum__TypeKindINPUT_OBJECT Enum__TypeKind = "INPUT_OBJECT"
45+
const Enum__TypeKindLIST Enum__TypeKind = "LIST"
46+
const Enum__TypeKindNON_NULL Enum__TypeKind = "NON_NULL"
47+
48+
type Enum__DirectiveLocation string
49+
50+
const Enum__DirectiveLocationQUERY Enum__DirectiveLocation = "QUERY"
51+
const Enum__DirectiveLocationMUTATION Enum__DirectiveLocation = "MUTATION"
52+
const Enum__DirectiveLocationSUBSCRIPTION Enum__DirectiveLocation = "SUBSCRIPTION"
53+
const Enum__DirectiveLocationFIELD Enum__DirectiveLocation = "FIELD"
54+
const Enum__DirectiveLocationFRAGMENT_DEFINITION Enum__DirectiveLocation = "FRAGMENT_DEFINITION"
55+
const Enum__DirectiveLocationFRAGMENT_SPREAD Enum__DirectiveLocation = "FRAGMENT_SPREAD"
56+
const Enum__DirectiveLocationINLINE_FRAGMENT Enum__DirectiveLocation = "INLINE_FRAGMENT"
57+
const Enum__DirectiveLocationSCHEMA Enum__DirectiveLocation = "SCHEMA"
58+
const Enum__DirectiveLocationSCALAR Enum__DirectiveLocation = "SCALAR"
59+
const Enum__DirectiveLocationOBJECT Enum__DirectiveLocation = "OBJECT"
60+
const Enum__DirectiveLocationFIELD_DEFINITION Enum__DirectiveLocation = "FIELD_DEFINITION"
61+
const Enum__DirectiveLocationARGUMENT_DEFINITION Enum__DirectiveLocation = "ARGUMENT_DEFINITION"
62+
const Enum__DirectiveLocationINTERFACE Enum__DirectiveLocation = "INTERFACE"
63+
const Enum__DirectiveLocationUNION Enum__DirectiveLocation = "UNION"
64+
const Enum__DirectiveLocationENUM Enum__DirectiveLocation = "ENUM"
65+
const Enum__DirectiveLocationENUM_VALUE Enum__DirectiveLocation = "ENUM_VALUE"
66+
const Enum__DirectiveLocationINPUT_OBJECT Enum__DirectiveLocation = "INPUT_OBJECT"
67+
const Enum__DirectiveLocationINPUT_FIELD_DEFINITION Enum__DirectiveLocation = "INPUT_FIELD_DEFINITION"
68+
69+
type __Schema struct {
70+
Types []__Type `json:"types"`
71+
QueryType __Type `json:"queryType"`
72+
MutationType *__Type `json:"mutationType"`
73+
SubscriptionType *__Type `json:"subscriptionType"`
74+
Directives []__Directive `json:"directives"`
75+
}
76+
77+
type __Type struct {
78+
Kind Enum__TypeKind `json:"kind"`
79+
Name *string `json:"name"`
80+
Description *string `json:"description"`
81+
Fields []__Field `json:"fields"`
82+
Interfaces []__Type `json:"interfaces"`
83+
PossibleTypes []__Type `json:"possibleTypes"`
84+
EnumValues []__EnumValue `json:"enumValues"`
85+
InputFields []__InputValue `json:"inputFields"`
86+
OfType *__Type `json:"ofType"`
87+
}
88+
89+
type __Field struct {
90+
Name string `json:"name"`
91+
Description *string `json:"description"`
92+
Args []__InputValue `json:"args"`
93+
Type __Type `json:"type"`
94+
IsDeprecated bool `json:"isDeprecated"`
95+
DeprecationReason *string `json:"deprecationReason"`
96+
}
97+
98+
type __InputValue struct {
99+
Name string `json:"name"`
100+
Description *string `json:"description"`
101+
Type __Type `json:"type"`
102+
DefaultValue *string `json:"defaultValue"`
103+
}
104+
105+
type __EnumValue struct {
106+
Name string `json:"name"`
107+
Description *string `json:"description"`
108+
IsDeprecated bool `json:"isDeprecated"`
109+
DeprecationReason *string `json:"deprecationReason"`
110+
}
111+
112+
type __Directive struct {
113+
Name string `json:"name"`
114+
Description *string `json:"description"`
115+
Locations []Enum__DirectiveLocation `json:"locations"`
116+
Args []__InputValue `json:"args"`
117+
}
118+
119+
type BuyerIdentity struct {
120+
Customer *Customer `json:"customer"`
121+
Email *string `json:"email"`
122+
Phone *string `json:"phone"`
123+
}
124+
125+
type Checkout struct {
126+
BuyerIdentity *BuyerIdentity `json:"buyerIdentity"`
127+
Cost CheckoutCost `json:"cost"`
128+
DeliveryGroups []*CheckoutDeliveryGroup `json:"deliveryGroups"`
129+
Lines []*CheckoutLine `json:"lines"`
130+
}
131+
132+
type CheckoutCost struct {
133+
SubtotalAmount Money `json:"subtotalAmount"`
134+
TotalAmount Money `json:"totalAmount"`
135+
TotalTaxAmount *Money `json:"totalTaxAmount"`
136+
}
137+
138+
type CheckoutDeliveryGroup struct {
139+
CheckoutLines []*CheckoutLine `json:"checkoutLines"`
140+
DeliveryAddress *MailingAddress `json:"deliveryAddress"`
141+
DeliveryOptions []*CheckoutDeliveryOption `json:"deliveryOptions"`
142+
Id []*string `json:"id"`
143+
SelectedDeliveryOption *CheckoutDeliveryOption `json:"selectedDeliveryOption"`
144+
}
145+
146+
type CheckoutDeliveryOption struct {
147+
Cost Money `json:"cost"`
148+
DeliveryMethodType *string `json:"deliveryMethodType"`
149+
Description string `json:"description"`
150+
Handle string `json:"handle"`
151+
Title *string `json:"title"`
152+
}
153+
154+
type CheckoutLine struct {
155+
Cost CheckoutLineCost `json:"cost"`
156+
Id string `json:"id"`
157+
Merchandise ProductVariant `json:"merchandise"`
158+
Quantity int64 `json:"quantity"`
159+
}
160+
161+
type CheckoutLineCost struct {
162+
SubtotalAmount Money `json:"subtotalAmount"`
163+
TotalAmount Money `json:"totalAmount"`
164+
}
165+
166+
type Customer struct {
167+
DisplayName string `json:"displayName"`
168+
Email *string `json:"email"`
169+
Id string `json:"id"`
170+
}
171+
172+
type ExchangeRate struct {
173+
Rate string `json:"rate"`
174+
}
175+
176+
type Input struct {
177+
Checkout Checkout `json:"checkout"`
178+
Localization Localization `json:"localization"`
179+
PaymentCustomizations []*PaymentCustomization `json:"paymentCustomizations"`
180+
PaymentMethods []*PaymentCustomizationPaymentMethod `json:"paymentMethods"`
181+
PresentmentCurrencyRate ExchangeRate `json:"presentmentCurrencyRate"`
182+
__schema __Schema `json:"__schema"`
183+
__type *__Type `json:"__type"`
184+
}
185+
186+
type Localization struct {
187+
Country string `json:"country"`
188+
Language string `json:"language"`
189+
}
190+
191+
type MailingAddress struct {
192+
Address1 *string `json:"address1"`
193+
Address2 *string `json:"address2"`
194+
City *string `json:"city"`
195+
Company *string `json:"company"`
196+
CountryCode *string `json:"countryCode"`
197+
FirstName *string `json:"firstName"`
198+
LastName *string `json:"lastName"`
199+
Name *string `json:"name"`
200+
Phone *string `json:"phone"`
201+
ProvinceCode *string `json:"provinceCode"`
202+
Zip *string `json:"zip"`
203+
}
204+
205+
type Metafield struct {
206+
Type string `json:"type"`
207+
Value string `json:"value"`
208+
}
209+
210+
type Money struct {
211+
Amount string `json:"amount"`
212+
CurrencyCode string `json:"currencyCode"`
213+
}
214+
215+
type PaymentCustomization struct {
216+
Metafield *Metafield `json:"metafield"`
217+
}
218+
219+
type PaymentCustomizationPaymentMethod struct {
220+
Id string `json:"id"`
221+
Name string `json:"name"`
222+
}
223+
224+
type Product struct {
225+
Handle string `json:"handle"`
226+
Id string `json:"id"`
227+
IsGiftCard bool `json:"isGiftCard"`
228+
}
229+
230+
type ProductVariant struct {
231+
Id string `json:"id"`
232+
Product Product `json:"product"`
233+
RequiresShipping bool `json:"requiresShipping"`
234+
Sku *string `json:"sku"`
235+
Weight *float64 `json:"weight"`
236+
WeightUnit *string `json:"weightUnit"`
237+
}

0 commit comments

Comments
 (0)