github.com/Ingenico-ePayments/connect-sdk-go@v0.0.0-20240318153750-1f8cd329b9c9/examples/merchant/hostedcheckouts/CreateHostedCheckoutExample.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/hostedcheckout"
    11  	"github.com/Ingenico-ePayments/connect-sdk-go/domain/payment"
    12  )
    13  
    14  func createHostedCheckoutExample() {
    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 hostedCheckoutSpecificInput hostedcheckout.SpecificInput
    27  	hostedCheckoutSpecificInput.Locale = newString("en_GB")
    28  	hostedCheckoutSpecificInput.Variant = newString("testVariant")
    29  
    30  	var amountOfMoney definitions.AmountOfMoney
    31  	amountOfMoney.Amount = newInt64(2345)
    32  	amountOfMoney.CurrencyCode = newString("USD")
    33  
    34  	var billingAddress definitions.Address
    35  	billingAddress.CountryCode = newString("US")
    36  
    37  	var customer payment.Customer
    38  	customer.BillingAddress = &billingAddress
    39  	customer.MerchantCustomerID = newString("1234")
    40  
    41  	var order payment.Order
    42  	order.AmountOfMoney = &amountOfMoney
    43  	order.Customer = &customer
    44  
    45  	var body hostedcheckout.CreateRequest
    46  	body.HostedCheckoutSpecificInput = &hostedCheckoutSpecificInput
    47  	body.Order = &order
    48  
    49  	response, err := client.Merchant("merchantId").Hostedcheckouts().Create(body, nil)
    50  
    51  	fmt.Println(response, err)
    52  }