Skip to content

Latest commit

 

History

History
189 lines (159 loc) · 20.3 KB

README.md

File metadata and controls

189 lines (159 loc) · 20.3 KB

LoggedIn

(Payments.LoggedIn)

Available Operations

Initialize

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.

Example Usage

package main

import(
	"github.com/BoltApp/bolt-go/models/components"
	"os"
	boltgo "github.com/BoltApp/bolt-go"
	"context"
	"log"
)

func main() {
    s := boltgo.New(
        boltgo.WithSecurity(components.Security{
            Oauth: boltgo.String(os.Getenv("OAUTH")),
        }),
    )
    var xPublishableKey string = "<value>"

    var xMerchantClientID string = "<value>"

    paymentInitializeRequest := components.PaymentInitializeRequest{
        Cart: components.Cart{
            OrderReference: "order_100",
            OrderDescription: boltgo.String("Order #1234567890"),
            DisplayID: boltgo.String("215614191"),
            Shipments: []components.CartShipment{
                components.CartShipment{
                    Address: 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",
                },
        ),
    }
    ctx := context.Background()
    res, err := s.Payments.LoggedIn.Initialize(ctx, xPublishableKey, xMerchantClientID, paymentInitializeRequest)
    if err != nil {
        log.Fatal(err)
    }
    if res.PaymentResponse != nil {
        // handle response
    }
}

Parameters

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.
xMerchantClientID string ✔️ A unique identifier for a shopper's device, generated by Bolt. This header is required for proper attribution of this operation to your analytics reports. Omitting this header may result in incorrect statistics.
paymentInitializeRequest components.PaymentInitializeRequest ✔️ N/A
opts []operations.Option The options for this request.

Response

*operations.PaymentsInitializeResponse, error

Error Object Status Code Content Type
sdkerrors.PaymentsInitializeResponseBody 4XX application/json
sdkerrors.SDKError 4xx-5xx /

PerformAction

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.

Example Usage

package main

import(
	"github.com/BoltApp/bolt-go/models/components"
	"os"
	boltgo "github.com/BoltApp/bolt-go"
	"context"
	"log"
)

func main() {
    s := boltgo.New(
        boltgo.WithSecurity(components.Security{
            Oauth: boltgo.String(os.Getenv("OAUTH")),
        }),
    )
    var id string = "iKv7t5bgt1gg"

    var xPublishableKey string = "<value>"

    var xMerchantClientID string = "<value>"

    paymentActionRequest := components.PaymentActionRequest{
        DotTag: components.PaymentActionRequestTagFinalize,
        RedirectResult: boltgo.String("eyJ0cmFuc"),
    }
    ctx := context.Background()
    res, err := s.Payments.LoggedIn.PerformAction(ctx, id, xPublishableKey, xMerchantClientID, paymentActionRequest)
    if err != nil {
        log.Fatal(err)
    }
    if res.PaymentResponse != nil {
        // handle response
    }
}

Parameters

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.
xMerchantClientID string ✔️ A unique identifier for a shopper's device, generated by Bolt. This header is required for proper attribution of this operation to your analytics reports. Omitting this header may result in incorrect statistics.
paymentActionRequest components.PaymentActionRequest ✔️ N/A
opts []operations.Option The options for this request.

Response

*operations.PaymentsActionResponse, error

Error Object Status Code Content Type
sdkerrors.PaymentsActionResponseBody 4XX application/json
sdkerrors.SDKError 4xx-5xx /