Skip to content

Commit 430f864

Browse files
feat: add new endpoint payment setups support (#191)
* add new endpoint payment setups support * chore: update GitHub Actions to use latest checkout and setup-go versions --------- Co-authored-by: Armando Rodríguez <127134616+armando-rodriguez-cko@users.noreply.github.com>
1 parent 585c731 commit 430f864

File tree

13 files changed

+990
-24
lines changed

13 files changed

+990
-24
lines changed

.github/workflows/build-master.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ jobs:
1515
- "1.14"
1616
- "1.18"
1717
steps:
18-
- uses: actions/checkout@v2
18+
- uses: actions/checkout@v5
1919
- id: setup-go
20-
uses: actions/setup-go@v1
20+
uses: actions/setup-go@v6
2121
with:
2222
go-version: ${{ matrix.go }}
2323
- id: build-and-test

.github/workflows/build-pull-request.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ jobs:
1515
- "1.14"
1616
- "1.18"
1717
steps:
18-
- uses: actions/checkout@v2
18+
- uses: actions/checkout@v5
1919
- id: setup-go
20-
uses: actions/setup-go@v1
20+
uses: actions/setup-go@v6
2121
with:
2222
go-version: ${{ matrix.go }}
2323
- id: build-and-test

.github/workflows/build-release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ jobs:
1414
go:
1515
- "1.14"
1616
steps:
17-
- uses: actions/checkout@v2
17+
- uses: actions/checkout@v5
1818
- id: setup-go
19-
uses: actions/setup-go@v1
19+
uses: actions/setup-go@v6
2020
with:
2121
go-version: ${{ matrix.go }}
2222
- id: build-and-test

abc/checkout_api.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
payments "github.com/checkout/checkout-sdk-go/payments/abc"
1414
"github.com/checkout/checkout-sdk-go/payments/hosted"
1515
"github.com/checkout/checkout-sdk-go/payments/links"
16+
"github.com/checkout/checkout-sdk-go/payments/setups"
1617
"github.com/checkout/checkout-sdk-go/reconciliation"
1718
"github.com/checkout/checkout-sdk-go/sources"
1819
"github.com/checkout/checkout-sdk-go/tokens"
@@ -27,6 +28,7 @@ type Api struct {
2728
Instruments *abc.Client
2829
Links *links.Client
2930
Payments *payments.Client
31+
PaymentSetups *setups.Client
3032
Reconciliation *reconciliation.Client
3133
Sources *sources.Client
3234
Tokens *tokens.Client
@@ -48,6 +50,7 @@ func CheckoutApi(configuration *configuration.Configuration) *Api {
4850
api.Instruments = abc.NewClient(configuration, apiClient)
4951
api.Links = links.NewClient(configuration, apiClient)
5052
api.Payments = payments.NewClient(configuration, apiClient)
53+
api.PaymentSetups = setups.NewClient(configuration, apiClient)
5154
api.Reconciliation = reconciliation.NewClient(configuration, apiClient)
5255
api.Sources = sources.NewClient(configuration, apiClient)
5356
api.Tokens = tokens.NewClient(configuration, apiClient)

nas/checkout_api.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/checkout/checkout-sdk-go/payments/links"
2222
payments "github.com/checkout/checkout-sdk-go/payments/nas"
2323
"github.com/checkout/checkout-sdk-go/payments/sessions"
24+
"github.com/checkout/checkout-sdk-go/payments/setups"
2425
"github.com/checkout/checkout-sdk-go/reports"
2526
"github.com/checkout/checkout-sdk-go/sessions"
2627
"github.com/checkout/checkout-sdk-go/tokens"
@@ -48,6 +49,7 @@ type Api struct {
4849
Issuing *issuing.Client
4950
Contexts *contexts.Client
5051
PaymentSessions *payment_sessions.Client
52+
PaymentSetups *setups.Client
5153
Forward *forward.Client
5254

5355
Ideal *ideal.Client
@@ -78,6 +80,7 @@ func CheckoutApi(configuration *configuration.Configuration) *Api {
7880
api.Issuing = issuing.NewClient(configuration, apiClient)
7981
api.Contexts = contexts.NewClient(configuration, apiClient)
8082
api.PaymentSessions = payment_sessions.NewClient(configuration, apiClient)
83+
api.PaymentSetups = setups.NewClient(configuration, apiClient)
8184
api.Forward = forward.NewClient(configuration, apiClient)
8285

8386
api.Ideal = ideal.NewClient(configuration, apiClient)

payments/payments.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -337,31 +337,31 @@ type (
337337
}
338338

339339
Ticket struct {
340-
Number string `json:"number,omitempty"`
341-
IssueDate string `json:"issue_date,omitempty"`
342-
IssuingCarrierCode string `json:"issuing_carrier_code,omitempty"`
343-
TravelPackageIndicator string `json:"travel_package_indicator,omitempty"`
344-
TravelAgencyName string `json:"travel_agency_name,omitempty"`
345-
TravelAgencyCode string `json:"travel_agency_code,omitempty"`
340+
Number string `json:"number,omitempty"`
341+
IssueDate *time.Time `json:"issue_date,omitempty"`
342+
IssuingCarrierCode string `json:"issuing_carrier_code,omitempty"`
343+
TravelPackageIndicator string `json:"travel_package_indicator,omitempty"`
344+
TravelAgencyName string `json:"travel_agency_name,omitempty"`
345+
TravelAgencyCode string `json:"travel_agency_code,omitempty"`
346346
}
347347

348348
Passenger struct {
349349
FirstName string `json:"first_name,omitempty"`
350350
LastName string `json:"last_name,omitempty"`
351-
DateOfBirth string `json:"date_of_birth,omitempty"`
351+
DateOfBirth *time.Time `json:"date_of_birth,omitempty"`
352352
Address *common.Address `json:"address,omitempty"`
353353
}
354354

355355
FlightLegDetails struct {
356-
FlightNumber string `json:"flight_number,omitempty"`
357-
CarrierCode string `json:"carrier_code,omitempty"`
358-
ClassOfTraveling string `json:"class_of_traveling,omitempty"`
359-
DepartureAirport string `json:"departure_airport,omitempty"`
360-
DepartureDate string `json:"departure_date,omitempty"`
361-
DepartureTime string `json:"departure_time,omitempty"`
362-
ArrivalAirport string `json:"arrival_airport,omitempty"`
363-
StopoverCode string `json:"stopover_code,omitempty"`
364-
FareBasisCode string `json:"fare_basis_code,omitempty"`
356+
FlightNumber string `json:"flight_number,omitempty"`
357+
CarrierCode string `json:"carrier_code,omitempty"`
358+
ClassOfTraveling string `json:"class_of_traveling,omitempty"`
359+
DepartureAirport string `json:"departure_airport,omitempty"`
360+
DepartureDate *time.Time `json:"departure_date,omitempty"`
361+
DepartureTime string `json:"departure_time,omitempty"`
362+
ArrivalAirport string `json:"arrival_airport,omitempty"`
363+
StopoverCode string `json:"stopover_code,omitempty"`
364+
FareBasisCode string `json:"fare_basis_code,omitempty"`
365365
}
366366

367367
ShippingInfo struct {

payments/setups/client.go

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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

Comments
 (0)