Skip to main content

getMissingVerificationForCoinbaseOnrampOrder

Checks what user verification is missing before creating a Coinbase onramp order. Coinbase requires verified email and phone number for Apple Pay purchases, and phone verification must be within the last 60 days. Call this function before createCoinbaseOnrampOrder to ensure the user has completed all required verification steps.

Usage

import { getMissingVerificationForCoinbaseOnrampOrder } from "@dynamic-labs-sdk/client";

const missingFields = getMissingVerificationForCoinbaseOnrampOrder({
  paymentMethod: "GUEST_CHECKOUT_APPLE_PAY",
});

if (missingFields.length > 0) {
  console.log("User needs to verify:", missingFields);
} else {
  console.log("User is ready to create an order");
}

Parameters

ParameterTypeDescription
paymentMethod"GUEST_CHECKOUT_APPLE_PAY"The payment method for the order. Currently only Apple Pay is supported.
clientDynamicClient (optional)The Dynamic client instance. Only required when using multiple clients.

Returns

FieldMissingVerificationForCoinbaseOnramp[] - An array of fields that need attention. Empty array means the user is ready.

Return type

type FieldMissingVerificationForCoinbaseOnramp =
  | {
      field: "email" | "phoneNumber";
      errorCode: "MISSING_INFORMATION";
    }
  | {
      field: "email" | "phoneNumber";
      errorCode: "MISSING_VERIFICATION" | "VERIFICATION_EXPIRED";
      data: string; // The unverified email or phone number
    };

Error Codes

CodeDescriptionAction Required
MISSING_INFORMATIONUser hasn’t provided email or phone number.Collect the information using updateUser.
MISSING_VERIFICATIONUser provided but hasn’t verified email or phone.Send OTP and verify using verifyOTP.
VERIFICATION_EXPIREDPhone verification is older than 60 days.Re-verify the phone number.

Complete Example

import {
  getMissingVerificationForCoinbaseOnrampOrder,
  createCoinbaseOnrampOrder,
  updateUser,
  sendEmailOTP,
  sendSmsOTP,
  verifyOTP,
} from "@dynamic-labs-sdk/client";

const prepareCoinbaseOrder = async (orderParams) => {
  const missing = getMissingVerificationForCoinbaseOnrampOrder({
    paymentMethod: "GUEST_CHECKOUT_APPLE_PAY",
  });

  // Handle each missing verification
  for (const field of missing) {
    if (field.field === "email") {
      if (field.errorCode === "MISSING_INFORMATION") {
        // Need to collect email from user
        const email = await promptUserForEmail();
        const result = await updateUser({ userFields: { email } });

        if (result?.verificationUUID) {
          // Email update requires verification
          const code = await promptUserForOTP("Check your email for a code");
          await verifyOTP({ otp: code, verificationUUID: result.verificationUUID });
        }
      } else if (field.errorCode === "MISSING_VERIFICATION") {
        // Email exists but not verified
        const result = await sendEmailOTP({ email: field.data });
        const code = await promptUserForOTP("Check your email for a code");
        await verifyOTP({ otp: code, verificationUUID: result.verificationUUID });
      }
    }

    if (field.field === "phoneNumber") {
      if (field.errorCode === "MISSING_INFORMATION") {
        // Need to collect phone number from user
        const phone = await promptUserForPhoneNumber();
        const result = await updateUser({ userFields: { phoneNumber: phone } });

        if (result?.verificationUUID) {
          const code = await promptUserForOTP("Check your phone for a code");
          await verifyOTP({ otp: code, verificationUUID: result.verificationUUID });
        }
      } else if (
        field.errorCode === "MISSING_VERIFICATION" ||
        field.errorCode === "VERIFICATION_EXPIRED"
      ) {
        // Phone exists but needs (re-)verification
        const result = await sendSmsOTP({ phoneNumber: field.data });
        const code = await promptUserForOTP("Check your phone for a code");
        await verifyOTP({ otp: code, verificationUUID: result.verificationUUID });
      }
    }
  }

  // Now the user is verified, create the order
  return createCoinbaseOnrampOrder(orderParams);
};

UI Component Example

import { getMissingVerificationForCoinbaseOnrampOrder } from "@dynamic-labs-sdk/client";

const VerificationStatus = () => {
  const missing = getMissingVerificationForCoinbaseOnrampOrder({
    paymentMethod: "GUEST_CHECKOUT_APPLE_PAY",
  });

  if (missing.length === 0) {
    return <p>Ready to purchase with Coinbase!</p>;
  }

  return (
    <div>
      <p>Please complete the following before purchasing:</p>
      <ul>
        {missing.map((item) => (
          <li key={item.field}>
            {item.field === "email" ? "Email" : "Phone number"}:{" "}
            {item.errorCode === "MISSING_INFORMATION"
              ? "Not provided"
              : item.errorCode === "MISSING_VERIFICATION"
                ? "Not verified"
                : "Verification expired (please re-verify)"}
          </li>
        ))}
      </ul>
    </div>
  );
};