Broadleaf Microservices
  • v1.0.0-latest-prod

PayPal Checkout Utility Methods

getHandleApproveOrder

Returns a callback to pass to the PayPalButtons for onApprove.

Parameters

Parameter

Type

Required?

Description

authState

AuthState

Information about the authentication state of the customer.

Response

Field

Type

Description

handleApproveOrder

HandleApproveOrder

The callback function to pass into PayPalButtons' onApprove parameter. Populates the paymentGatewayProperties for Payment creation in PaymentTransactionServices.

HandleApproveOrder

Parameter

Type

Required?

Description

handleApproveOrder

Function

The callback function to pass into PayPalButtons' onApprove parameter. Returns address, attributes, and paymentGatewayProperties.

Example Usage

const handleApproveOrder = getHandleApproveOrder({ authState });
const onSubmit = useCallback(
  async (data, actions) => {
    const { attributes, paymentGatewayProperties } = await handleApproveOrder(
      data,
      actions
    );

    const paymentRequest = {
        ...
        paymentGatewayProperties,
        attributes,
    } as PaymentRequest;

    // add payment with paymentRequest payload
})

getHandleCreateOrder

Returns a callback to pass to the PayPalButtons for handleCreate.

Parameters

Parameter

Type

Required?

Description

config

CreateOrderConfig

The configuration needed to create the order.

CreateOrderConfig

Name Type Required? Description

cartState

CartState

Important information about the state of the cart.

shippingPreference

enum

The shipping preference to be specified on the application context. See PayPal’s application context definition for more details.

setError

Function

Used to track the error state, e.g. setError: (error: unknown) ⇒ void;

Response

Field

Type

Description

createOrder

createOrder callback function

The callback function to pass into PayPalButtons' createOrder parameter.

Example Usage

const createOrder = getHandleCreateOrder({
  cartState,
  shippingPreference,
  setError,
});

getPaymentReviewDisplay

Returns the email attribute associated with the PayPal account from the PaymentSummary.

Parameters

Parameter

Type

Required?

Description

payment

Payment Summary

The payment summary to display for review.

Response

Field

Type

Description

paymentDisplay

string

The email attribute from the payment summary associated with the PayPal account.

Example Usage

const paymentDisplay = getPaymentReviewDisplay(payment);