github.com/Ingenico-ePayments/connect-sdk-go@v0.0.0-20240318153750-1f8cd329b9c9/examples/merchant/captures/CreateRefundCaptureExample.go (about) 1 // This file was auto-generated from the API references found at 2 // https://epayments-api.developer-ingenico.com/ 3 4 package examples 5 6 import ( 7 "fmt" 8 9 "github.com/Ingenico-ePayments/connect-sdk-go/domain/definitions" 10 "github.com/Ingenico-ePayments/connect-sdk-go/domain/refund" 11 sdkErrors "github.com/Ingenico-ePayments/connect-sdk-go/errors" 12 ) 13 14 func createRefundCaptureExample() { 15 client, clientErr := getClient() 16 if clientErr != nil { 17 panic(clientErr) 18 } 19 defer client.Close() 20 21 // Assigning literals to pointer variables directly is not supported. 22 // The below code uses helper functions newInt64 and newString to overcome this issue. 23 // http://stackoverflow.com/a/30716481 lists a few more alternatives. 24 // The code for these helper functions can be found in file Helper.go 25 26 var amountOfMoney definitions.AmountOfMoney 27 amountOfMoney.Amount = newInt64(500) 28 amountOfMoney.CurrencyCode = newString("EUR") 29 30 var refundReferences refund.References 31 refundReferences.MerchantReference = newString("AcmeOrder0001") 32 33 var body refund.Request 34 body.AmountOfMoney = &amountOfMoney 35 body.RefundReferences = &refundReferences 36 37 response, err := client.Merchant("merchantId").Captures().Refund("captureId", body, nil) 38 switch realError := err.(type) { 39 case *sdkErrors.DeclinedRefundError: 40 { 41 handleDeclinedRefund(realError.RefundResult()) 42 43 break 44 } 45 case sdkErrors.APIError: 46 { 47 handleAPIErrors(realError.Errors()) 48 49 break 50 } 51 } 52 53 fmt.Println(response, err) 54 }