> ## Documentation Index
> Fetch the complete documentation index at: https://docs.unprice.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Create payment method

> Create a payment method for a customer

<RequestExample>
  ```ts theme={null}
  const { result, error } = await unprice.paymentMethods.create({
    customerId: "cus_1234567890",
    paymentProvider: "stripe",
    successUrl: "https://example.com/success",
    cancelUrl: "https://example.com/cancel"
  });

  if (error) {
    // handle potential network or bad request error
    // a link to our docs will be in the `error.docs` field
    console.error(error.message);
    return;
  }

  console.log(result);
  ```
</RequestExample>

<ResponseExample>
  ```json theme={null}
  {
    "success": true,
    "url": "https://checkout.stripe.com/pay/cs_test_1234567890"
  }
  ```
</ResponseExample>

## Request

<ParamField body="customerId" type="string" required>
  The ID of the customer to create a payment method for
</ParamField>

<ParamField body="paymentProvider" type="string" enum="stripe,square" required>
  The payment provider to use
</ParamField>

<ParamField body="successUrl" type="string" required>
  The URL to redirect to after successful payment method creation
</ParamField>

<ParamField body="cancelUrl" type="string" required>
  The URL to redirect to if payment method creation is canceled
</ParamField>

## Response

<ResponseField name="success" type="boolean" required>
  Whether the payment method creation was successful
</ResponseField>

<ResponseField name="url" type="string" required>
  The URL to redirect the customer to for payment method creation
</ResponseField>
