NOWPayments “Pay with Crypto” Button – Payment Creation Fails on Cart Page

Hi all,

I’m trying to integrate a custom “Pay with Crypto” button on my Shopify cart page, using the NOWPayments API. The button appears and triggers the script properly — but when clicked, I get a “Payment creation failed. Please try again.” message from the script.

Here’s the button code (with API key removed for privacy):

<button
id=“crypto-cart-button”
type=“button”
style=“margin-top: 12px; width: 100%; padding: 14px 28px; background-color: transparent; color: white; border: 1.5px solid white; font-size: 16px; font-weight: 300; letter-spacing: 1px; text-transform: uppercase; cursor: pointer; transition: all 0.3s ease;”
onmouseover=“this.style.backgroundColor=‘white’; this.style.color=‘black’;”
onmouseout=“this.style.backgroundColor=‘transparent’; this.style.color=‘white’;”

Pay with Crypto

Issue:

When the button is clicked:

  • The API call seems to execute.
  • But I get a “Payment creation failed” alert.
  • This means the POST request was made, but the payment_url was not returned.

I’ve double-checked that price_amount is pulling from cart.items_subtotal_price / 100, and that part appears to work.

Any ideas what could be preventing the payment creation from succeeding with NOWPayments on the cart page?

Thanks so much in advance!

Cheers,

Rowan

Hi @IRedefined

I am from Mageplaza - Shopify solution expert.

Your setup is mostly correct, and it’s great that you’re already fetching the cart data and handling the button interaction smoothly. The issue seems to lie in the structure or completeness of the paymentData object that is being sent to the NOWPayments API.

Here are common reasons why payment_url may not be returned, and how to fix them:

1. Missing pay_currency
NOWPayments sometimes requires a pay_currency field in addition to price_currency. If it’s not set, the API may silently fail to generate a payment_url.

Fix:
Add a pay_currency field — for example, let the customer pay in BTC or another supported coin:

pay_currency: "btc",

2. Invalid or Missing API Key
Ensure the API key is valid and has the required permissions in your NOWPayments dashboard. A bad key might not return a helpful error, just fail silently.

Double-check:

The key is correct and active

It allows payments in the currencies you are setting (price_currency, pay_currency)

3. Not Including Required Fields
Your current paymentData lacks the ipn_callback_url, which is often optional but sometimes required based on your account settings.

Optional Fix:
If you have an endpoint to receive status updates:

ipn_callback_url: "https://yourshopifydomain.com/nowpayments-callback"

4. Invalid Amount Format
Ensure price_amount is a proper number (not a string, NaN, etc.) and not 0.

Your current code does:

const priceAmount = cart.items_subtotal_price / 100;

That’s good. Consider rounding it to two decimal places to avoid issues:

const priceAmount = (cart.items_subtotal_price / 100).toFixed(2);

Make sure to convert back to a number:

price_amount: parseFloat(priceAmount),

5. Logging the Full API Response
To debug better, log data fully before checking for payment_url.

Update this line:

if (data && data.payment_url) {

To this:

console.log('NOWPayments API response:', data);
if (data && data.payment_url) {

This will show if there’s an actual error message in the response.

Updated paymentData Example:

const paymentData = {
  price_amount: parseFloat((cart.items_subtotal_price / 100).toFixed(2)),
  price_currency: "usd",
  pay_currency: "btc", // <-- try BTC for testing
  order_id: "cart_" + Math.floor(Math.random() * 1000000),
  order_description: "Cart purchase from Intimacy Redefined"
  // ipn_callback_url: "https://yourshopifydomain.com/nowpayments-callback" // optional
};

Final Tip: Try the API in Postman or curl
To isolate whether the issue is in your frontend or the API call itself, try creating a payment manually via Postman with the same paymentData. If it fails there, it’s most likely data or API key related.

Please let me know if it works as expected

Best regards!

Hi Mageplaza,

Thank you very much for your message. I’ve hired a Shopify developer to integrate the API.

Best,
Rowan