Create a Payment Source

Create a payment sources.

Easyship won't hold the details of your credit card. We use stripe token to attach the credit card to your easyship account on Stripe.
Please upload your credit card to stripe via Stripe Token JS.

Example:

Stripe Token JS Example
<script src="https://js.stripe.com/v3/"></script>
<script>
  // Retrieve Easyship stripe publishable api key through `GET /2024-09/account/stripe`
  var stripe = Stripe('stripe_publishable_api_key');

  // Create an instance of Elements.
  // https://stripe.com/docs/js/elements_object/create_element?type=card
  var elements = stripe.elements();

  // Create a CardElement
  var card = elements.create('card')

  // Create your token from the CardElement data
  // https://stripe.com/docs/js/tokens/create_token?type=cardElement
  stripe.createToken(card).then(function (result) {
    if (result.error) {
      // error handling
    } else {
      // You would receive the `stripe token` with prefix `tok_`.
      // `POST /2024-09/payment_sources` here to attach your card to Easyship
      var token = result.token;
    }
  });
</script>

When the credit card needs 3DS (with response status code 202), proceed with the next step found in POST /2024-09/payment_sources/confirm.

If the payment source type is bank account, you'll receive a status code 202, indicating the need to submit the bank account information.
Easyship won't hold the details of your bank account. We use setup intent to attach the bank account to your easyship account on Stripe.

Note: A bank account payment source is only available for US companies.

Example:

Stripe Bank Account JS Example
  <script>
    // Retrieve Easyship stripe publishable api key through `GET /2024-09/account/stripe`
    const stripe = Stripe('stripe_publishable_api_key');

    // Use the form that already exists on the web page.
    const paymentMethodForm = document.getElementById('payment-method-form');

    paymentMethodForm.addEventListener('submit', (ev) => {
      ev.preventDefault();
      const accountHolderNameField = document.getElementById('account-holder-name');
      const emailField = document.getElementById('email-field');

      // Retrieve the client secret from POST /2024-09/payment_sources.
      const clientSecretField = document.getElementById('client-secret-field');

      // Calling this method will open the dialog to submit bank account information.
      stripe.collectBankAccountForSetup({
        clientSecret: clientSecretField.value,
        params: {
          payment_method_type: 'us_bank_account',
          payment_method_data: {
            billing_details: {
              name: accountHolderNameField.value,
              email: emailField.value,
            },
          },
        }
      })
      .then(({setupIntent, error}) => {
        if (error) {
          console.error(error.message);
        } else {
          // POST /2024-09/payment_sources/confirm to finalize the bank account payment source at Easyship
        }
      });
    });
  </script>

Once the bank account information has been submitted successfully, proceed with the next step found in POST /2024-09/payment_sources/confirm.

Required authorization scope: public.payment_source:write

Language
Credentials
Bearer
token
Click Try It! to start a request and see the response here!