@@ -18,11 +18,11 @@ class ShopifyGiftCardService
1818 def initialize ( shop : Rails . application . config . shopify_shop_domain , token : Rails . application . config . shopify_admin_access_token )
1919 @session = ShopifyAPI ::Auth ::Session . new ( shop : shop , access_token : token )
2020 @client = ShopifyAPI ::Clients ::Graphql ::Admin . new ( session : @session )
21- log_debug ( "ShopifyGiftCardService initialized" , shop : shop )
2221 end
2322
2423 def create_gift_card ( amount , name = nil , note : nil )
25- log_info ( "Creating gift card via Shopify API" , amount : amount , name : name )
24+ log_info ( "Creating gift card via Shopify" ,
25+ "gibpotato.giftcard.amount" : amount )
2626
2727 begin
2828 variables = build_mutation_variables ( amount , name , note )
@@ -45,7 +45,6 @@ def build_mutation_variables(amount, name, note)
4545 end
4646
4747 def execute_graphql_mutation ( variables )
48- log_trace ( "Executing Shopify GraphQL mutation" , variables : variables )
4948 @client . query ( query : CREATE_MUTATION , variables : variables )
5049 end
5150
@@ -68,10 +67,9 @@ def extract_user_errors(payload)
6867 end
6968
7069 def handle_user_errors ( errors , amount , name )
71- log_error ( "Shopify API returned user errors" ,
72- errors : errors ,
73- amount : amount ,
74- name : name )
70+ log_error ( "Shopify returned user errors creating gift card" ,
71+ "gibpotato.giftcard.amount" : amount ,
72+ "gibpotato.giftcard.user_errors" : errors )
7573 error! ( errors . join ( ", " ) )
7674 end
7775
@@ -82,19 +80,18 @@ def build_success_response(payload)
8280 "code" => payload [ "giftCardCode" ]
8381 }
8482
85- log_info ( "Gift card created successfully via Shopify" ,
86- gift_card_id : gift_card_data [ "id" ] ,
87- amount : gift_card_data [ "amount" ] )
83+ log_info ( "Gift card created via Shopify" ,
84+ "gibpotato.giftcard.id" : gift_card_data [ "id" ] ,
85+ "gibpotato.giftcard. amount" : gift_card_data [ "amount" ] )
8886
8987 success! ( gift_card : gift_card_data )
9088 end
9189
9290 def handle_api_error ( error , amount , name )
93- log_error ( "Shopify API error occurred" ,
94- error_message : error . message ,
95- error_class : error . class . name ,
96- amount : amount ,
97- name : name )
91+ log_error ( "Shopify API request failed" ,
92+ "gibpotato.giftcard.amount" : amount ,
93+ "gibpotato.giftcard.error_class" : error . class . name ,
94+ "gibpotato.giftcard.error_message" : error . message )
9895 error! ( "Shopify error: #{ error . message } " )
9996 end
10097
0 commit comments