|
| 1 | +package setups |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/checkout/checkout-sdk-go/client" |
| 5 | + "github.com/checkout/checkout-sdk-go/common" |
| 6 | + "github.com/checkout/checkout-sdk-go/configuration" |
| 7 | +) |
| 8 | + |
| 9 | +type Client struct { |
| 10 | + configuration *configuration.Configuration |
| 11 | + apiClient client.HttpClient |
| 12 | +} |
| 13 | + |
| 14 | +func NewClient(configuration *configuration.Configuration, apiClient client.HttpClient) *Client { |
| 15 | + return &Client{ |
| 16 | + configuration: configuration, |
| 17 | + apiClient: apiClient, |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +// CreatePaymentSetup creates a Payment Setup. |
| 22 | +// Beta |
| 23 | +// |
| 24 | +// Creates a Payment Setup. |
| 25 | +// |
| 26 | +// To maximize the amount of information the payment setup can use, we |
| 27 | +// recommend that you create a payment setup as early as possible in the |
| 28 | +// customer's journey. For example, the first time they land on the basket |
| 29 | +// page. |
| 30 | +func (c *Client) CreatePaymentSetup(request PaymentSetupRequest) (*PaymentSetupResponse, error) { |
| 31 | + auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth) |
| 32 | + if err != nil { |
| 33 | + return nil, err |
| 34 | + } |
| 35 | + |
| 36 | + var response PaymentSetupResponse |
| 37 | + err = c.apiClient.Post(common.BuildPath(PaymentSetupsPath), auth, request, &response, nil) |
| 38 | + if err != nil { |
| 39 | + return nil, err |
| 40 | + } |
| 41 | + |
| 42 | + return &response, nil |
| 43 | +} |
| 44 | + |
| 45 | +// UpdatePaymentSetup updates a Payment Setup. |
| 46 | +// Beta |
| 47 | +// |
| 48 | +// Updates a Payment Setup. |
| 49 | +// |
| 50 | +// You should update the payment setup whenever there are significant changes |
| 51 | +// in the data relevant to the customer's transaction. For example, when the |
| 52 | +// customer makes a change that impacts the total payment amount. |
| 53 | +func (c *Client) UpdatePaymentSetup(setupId string, request PaymentSetupRequest) (*PaymentSetupResponse, error) { |
| 54 | + auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth) |
| 55 | + if err != nil { |
| 56 | + return nil, err |
| 57 | + } |
| 58 | + |
| 59 | + var response PaymentSetupResponse |
| 60 | + err = c.apiClient.Put(common.BuildPath(PaymentSetupsPath, setupId), auth, request, &response, nil) |
| 61 | + if err != nil { |
| 62 | + return nil, err |
| 63 | + } |
| 64 | + |
| 65 | + return &response, nil |
| 66 | +} |
| 67 | + |
| 68 | +// GetPaymentSetup retrieves a Payment Setup. |
| 69 | +// Beta |
| 70 | +// |
| 71 | +// Retrieves a Payment Setup. |
| 72 | +func (c *Client) GetPaymentSetup(setupId string) (*PaymentSetupResponse, error) { |
| 73 | + auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth) |
| 74 | + if err != nil { |
| 75 | + return nil, err |
| 76 | + } |
| 77 | + |
| 78 | + var response PaymentSetupResponse |
| 79 | + err = c.apiClient.Get(common.BuildPath(PaymentSetupsPath, setupId), auth, &response) |
| 80 | + if err != nil { |
| 81 | + return nil, err |
| 82 | + } |
| 83 | + |
| 84 | + return &response, nil |
| 85 | +} |
| 86 | + |
| 87 | +// ConfirmPaymentSetup confirms a Payment Setup to begin processing the |
| 88 | +// payment request with your chosen payment method option. |
| 89 | +// Beta |
| 90 | +// |
| 91 | +// Confirm a Payment Setup to begin processing the payment request with your |
| 92 | +// chosen payment method option. |
| 93 | +func (c *Client) ConfirmPaymentSetup(setupId string, paymentMethodOptionId string) (*PaymentSetupConfirmResponse, error) { |
| 94 | + auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth) |
| 95 | + if err != nil { |
| 96 | + return nil, err |
| 97 | + } |
| 98 | + |
| 99 | + var response PaymentSetupConfirmResponse |
| 100 | + err = c.apiClient.Post(common.BuildPath(PaymentSetupsPath, setupId, ConfirmPath, paymentMethodOptionId), auth, nil, &response, nil) |
| 101 | + if err != nil { |
| 102 | + return nil, err |
| 103 | + } |
| 104 | + |
| 105 | + return &response, nil |
| 106 | +} |
0 commit comments