Skip to content

Latest commit

 

History

History
310 lines (229 loc) · 22.5 KB

README.md

File metadata and controls

310 lines (229 loc) · 22.5 KB

PolarCustomers

(CustomerPortal.Customers)

Overview

Available Operations

Get

Get authenticated customer.

Scopes: customer_portal:read customer_portal:write

Example Usage

package main

import(
	"context"
	polargo "github.com/polarsource/polar-go"
	"os"
	"github.com/polarsource/polar-go/models/operations"
	"log"
)

func main() {
    ctx := context.Background()

    s := polargo.New()

    res, err := s.CustomerPortal.Customers.Get(ctx, operations.CustomerPortalCustomersGetSecurity{
        CustomerSession: os.Getenv("POLAR_CUSTOMER_SESSION"),
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.CustomerPortalCustomer != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
security operations.CustomerPortalCustomersGetSecurity ✔️ The security requirements to use for the request.
opts []operations.Option The options for this request.

Response

*operations.CustomerPortalCustomersGetResponse, error

Errors

Error Type Status Code Content Type
apierrors.APIError 4XX, 5XX */*

Update

Update authenticated customer.

Scopes: customer_portal:write

Example Usage

package main

import(
	"context"
	polargo "github.com/polarsource/polar-go"
	"github.com/polarsource/polar-go/models/components"
	"os"
	"github.com/polarsource/polar-go/models/operations"
	"log"
)

func main() {
    ctx := context.Background()

    s := polargo.New()

    res, err := s.CustomerPortal.Customers.Update(ctx, components.CustomerPortalCustomerUpdate{}, operations.CustomerPortalCustomersUpdateSecurity{
        CustomerSession: os.Getenv("POLAR_CUSTOMER_SESSION"),
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.CustomerPortalCustomer != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request components.CustomerPortalCustomerUpdate ✔️ The request object to use for the request.
security operations.CustomerPortalCustomersUpdateSecurity ✔️ The security requirements to use for the request.
opts []operations.Option The options for this request.

Response

*operations.CustomerPortalCustomersUpdateResponse, error

Errors

Error Type Status Code Content Type
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*

GetPaymentMethods

Get saved payment methods of the authenticated customer.

Scopes: customer_portal:read customer_portal:write

Example Usage

package main

import(
	"context"
	polargo "github.com/polarsource/polar-go"
	"os"
	"github.com/polarsource/polar-go/models/operations"
	"log"
)

func main() {
    ctx := context.Background()

    s := polargo.New()

    res, err := s.CustomerPortal.Customers.GetPaymentMethods(ctx, operations.CustomerPortalCustomersGetPaymentMethodsSecurity{
        CustomerSession: os.Getenv("POLAR_CUSTOMER_SESSION"),
    }, nil, nil)
    if err != nil {
        log.Fatal(err)
    }
    if res.ListResourceUnionPaymentMethodCardPaymentMethodGeneric != nil {
        for {
            // handle items

            res, err = res.Next()

            if err != nil {
                // handle error
            }

            if res == nil {
                break
            }
        }
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
security operations.CustomerPortalCustomersGetPaymentMethodsSecurity ✔️ The security requirements to use for the request.
page *int64 Page number, defaults to 1.
limit *int64 Size of a page, defaults to 10. Maximum is 100.
opts []operations.Option The options for this request.

Response

*operations.CustomerPortalCustomersGetPaymentMethodsResponse, error

Errors

Error Type Status Code Content Type
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*

AddPaymentMethod

Add a payment method to the authenticated customer.

Scopes: customer_portal:read customer_portal:write

Example Usage

package main

import(
	"context"
	polargo "github.com/polarsource/polar-go"
	"github.com/polarsource/polar-go/models/components"
	"os"
	"github.com/polarsource/polar-go/models/operations"
	"log"
)

func main() {
    ctx := context.Background()

    s := polargo.New()

    res, err := s.CustomerPortal.Customers.AddPaymentMethod(ctx, components.CustomerPaymentMethodCreate{
        ConfirmationTokenID: "<id>",
        SetDefault: false,
        ReturnURL: "https://slight-digestive.info",
    }, operations.CustomerPortalCustomersAddPaymentMethodSecurity{
        CustomerSession: os.Getenv("POLAR_CUSTOMER_SESSION"),
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.ResponseCustomerPortalCustomersAddPaymentMethod != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request components.CustomerPaymentMethodCreate ✔️ The request object to use for the request.
security operations.CustomerPortalCustomersAddPaymentMethodSecurity ✔️ The security requirements to use for the request.
opts []operations.Option The options for this request.

Response

*operations.CustomerPortalCustomersAddPaymentMethodResponse, error

Errors

Error Type Status Code Content Type
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*

DeletePaymentMethod

Delete a payment method from the authenticated customer.

Scopes: customer_portal:read customer_portal:write

Example Usage

package main

import(
	"context"
	polargo "github.com/polarsource/polar-go"
	"os"
	"github.com/polarsource/polar-go/models/operations"
	"log"
)

func main() {
    ctx := context.Background()

    s := polargo.New()

    res, err := s.CustomerPortal.Customers.DeletePaymentMethod(ctx, operations.CustomerPortalCustomersDeletePaymentMethodSecurity{
        CustomerSession: os.Getenv("POLAR_CUSTOMER_SESSION"),
    }, "<id>")
    if err != nil {
        log.Fatal(err)
    }
    if res != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
security operations.CustomerPortalCustomersDeletePaymentMethodSecurity ✔️ The security requirements to use for the request.
id string ✔️ N/A
opts []operations.Option The options for this request.

Response

*operations.CustomerPortalCustomersDeletePaymentMethodResponse, error

Errors

Error Type Status Code Content Type
apierrors.ResourceNotFound 404 application/json
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*