(Payments.LoggedIn)
- Initialize - Initialize a Bolt payment for logged in shoppers
- PerformAction - Finalize a pending payment
Initialize a Bolt logged-in shopper's intent to pay for a cart, using the specified payment method. Payments must be finalized before indicating the payment result to the shopper. Some payment methods will finalize automatically after initialization. For these payments, they will transition directly to "finalized" and the response from Initialize Payment will contain a finalized payment.
package main
import(
"context"
boltgo "github.com/BoltApp/bolt-go"
"github.com/BoltApp/bolt-go/models/components"
"log"
)
func main() {
ctx := context.Background()
s := boltgo.New(
boltgo.WithSecurity(components.Security{
Oauth: boltgo.String("<YOUR_OAUTH_HERE>"),
APIKey: boltgo.String("<YOUR_API_KEY_HERE>"),
}),
)
res, err := s.Payments.LoggedIn.Initialize(ctx, "<value>", components.PaymentInitializeRequest{
Cart: components.Cart{
OrderReference: "order_100",
OrderDescription: boltgo.String("Order #1234567890"),
DisplayID: boltgo.String("215614191"),
Shipments: []components.CartShipment{
components.CartShipment{
Address: boltgo.Pointer(components.CreateAddressReferenceInputAddressReferenceID(
components.AddressReferenceID{
DotTag: components.AddressReferenceIDTagID,
ID: "D4g3h5tBuVYK9",
},
)),
Cost: &components.Amount{
Currency: components.CurrencyUsd,
Units: 10000,
},
Carrier: boltgo.String("FedEx"),
},
},
Discounts: []components.CartDiscount{
components.CartDiscount{
Amount: components.Amount{
Currency: components.CurrencyUsd,
Units: 10000,
},
Code: boltgo.String("SUMMER10DISCOUNT"),
DetailsURL: boltgo.String("https://www.example.com/SUMMER-SALE"),
},
},
Items: []components.CartItem{
components.CartItem{
Name: "Bolt Swag Bag",
Reference: "item_100",
Description: boltgo.String("Large tote with Bolt logo."),
TotalAmount: components.Amount{
Currency: components.CurrencyUsd,
Units: 9000,
},
UnitPrice: 1000,
Quantity: 9,
ImageURL: boltgo.String("https://www.example.com/products/123456/images/1.png"),
},
},
Total: components.Amount{
Currency: components.CurrencyUsd,
Units: 9000,
},
Tax: components.Amount{
Currency: components.CurrencyUsd,
Units: 100,
},
},
PaymentMethod: components.CreatePaymentMethodExtendedPaymentMethodReference(
components.PaymentMethodReference{
DotTag: components.PaymentMethodReferenceTagID,
ID: "X5h6j8uLpVGK",
},
),
}, boltgo.String("<value>"))
if err != nil {
log.Fatal(err)
}
if res.PaymentResponse != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
xPublishableKey |
string | ✔️ | The publicly shareable identifier used to identify your Bolt merchant division. |
paymentInitializeRequest |
components.PaymentInitializeRequest | ✔️ | N/A |
xMerchantClientID |
*string | ➖ | A unique identifier for a shopper's device, generated by Bolt. The value is retrieved with Bolt.state.merchantClientId in your frontend context, per-shopper. This header is required for proper attribution of this operation to your analytics reports. Omitting this header may result in incorrect statistics. |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.PaymentsInitializeResponse, error
Error Type | Status Code | Content Type |
---|---|---|
sdkerrors.PaymentsInitializeResponseBody | 4XX | application/json |
sdkerrors.SDKError | 5XX | */* |
Finalize a pending payment being made by a Bolt logged-in shopper. Upon receipt of a finalized payment result, payment success should be communicated to the shopper.
package main
import(
"context"
boltgo "github.com/BoltApp/bolt-go"
"github.com/BoltApp/bolt-go/models/components"
"log"
)
func main() {
ctx := context.Background()
s := boltgo.New(
boltgo.WithSecurity(components.Security{
Oauth: boltgo.String("<YOUR_OAUTH_HERE>"),
APIKey: boltgo.String("<YOUR_API_KEY_HERE>"),
}),
)
res, err := s.Payments.LoggedIn.PerformAction(ctx, "iKv7t5bgt1gg", "<value>", components.PaymentActionRequest{
DotTag: components.PaymentActionRequestTagFinalize,
RedirectResult: boltgo.String("eyJ0cmFuc"),
}, boltgo.String("<value>"))
if err != nil {
log.Fatal(err)
}
if res.PaymentResponse != nil {
// handle response
}
}
Parameter | Type | Required | Description | Example |
---|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. | |
id |
string | ✔️ | The ID of the payment to operate on | iKv7t5bgt1gg |
xPublishableKey |
string | ✔️ | The publicly shareable identifier used to identify your Bolt merchant division. | |
paymentActionRequest |
components.PaymentActionRequest | ✔️ | N/A | |
xMerchantClientID |
*string | ➖ | A unique identifier for a shopper's device, generated by Bolt. The value is retrieved with Bolt.state.merchantClientId in your frontend context, per-shopper. This header is required for proper attribution of this operation to your analytics reports. Omitting this header may result in incorrect statistics. |
|
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.PaymentsActionResponse, error
Error Type | Status Code | Content Type |
---|---|---|
sdkerrors.PaymentsActionResponseBody | 4XX | application/json |
sdkerrors.SDKError | 5XX | */* |