Why is my code for creating a customer credit card not working?

Why is my code for creating a customer credit card not working?

ELHAFIDI
Shopify Partner
3 0 0
 this is my code but it is not working ? 
 const Createcreditcard = async () => {
    const mutationData = {
      query: `
        mutation CreateCreditCard {
          customerPaymentMethodCreditCardCreate(
            billingAddress: {
              address1: "123 Test St",
              city: "Test City",
              province: "Test Province",
              zip: "12345",
              country: "US"
            },
            customerId: "gid://shopify/Customer/756686418768",
            sessionId: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkZXN0IjoieHRyeS1tZWNob3VoLm15c2hvcGlmeS5jb20iLCJhdWQiOiIwZmUzNjJlZWQ5M2VjOGFlN2U2M2QxN2JlZjM2Njg1NiIsImV4cCI6MTcwNTY3MTg2NSwibmJmIjoxNzA1NjcxNTY1LCJpYXQiOjE3MDU2NzE1NjUsImp0aSI6IjZhMmY4NzE5LTE0ODMtNDk4Yi04OTAwLTI2YTUxYzMzYmY1MyIsInN1YiI6ImdpZDpcL1wvc2hvcGlmeVwvQ3VzdG9tZXJcLzc1NjY4NjQxODc2ODAifQ.QpJN_QOnodebSHmbN5Z9tVKP6KpBVpvk6J-S6jEhd2c"
          ) {
            customerPaymentMethod {
              id
            }
            processing
            userErrors {
              field
              message
            }
          }
        }
      `,
    };
 
    try {
      const response = await fetch("shopify://customer-account/api/unstable/graphql.json", {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          "X-Shopify-Storefront-Access-Token": "6e7816e07e1b9119dd6162abc6b8d546",
        },
        body: JSON.stringify(mutationData),
      });
 
      const responseData = await response.json();
      if (responseData.errors) {
        console.error("GraphQL Mutation Error:", responseData.errors);
        return;
      }
 
      console.log("New Payment Method ID:", responseData.data.customerPaymentMethodCreditCardCreate.customerPaymentMethod.id);
    } catch (error) {
      console.error("Error creating payment method:", error);
    }
  };
 
 
Replies 0 (0)