#IVAŁDØ

1 messages · Page 1 of 1 (latest)

muted zephyrBOT
raven oak
#

Hello! Is this your own integration? Is this a sample you're working with?

void pawn
#

Stripe Issuing lets you to create, manage, and distribute virtual and physical cards programmatically. You can create set spending limits, control expenses, set allowed business type, designate virtual cards for one-time or multiple uses.

In this episode, Stripe developer advocate CJ Avilla, demonstrates how easy it is to create a new cardholde...

▶ Play video
#

i can send my code snippets

#
const app = express();
const { resolve } = require('path');
// Replace if using a different env file or config
const env = require('dotenv').config({ path: './.env' });

const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY, {
  apiVersion: '2020-08-27',
  appInfo: { // For sample support and debugging, not required for production:
    name: "stripe-samples/<your-sample-name>",
    version: "0.0.1",
    url: "https://github.com/stripe-samples"
  }
});

app.use(express.static(process.env.STATIC_DIR));
app.use(express.urlencoded());
app.use(
  express.json({
    // We need the raw body to verify webhook signatures.
    // Let's compute it only when hitting the Stripe webhook endpoint.
    verify: function(req, res, buf) {
      if (req.originalUrl.startsWith('/webhook')) {
        req.rawBody = buf.toString();
      }
    }
  })
);

app.get('/', (req, res) => {
  const path = resolve(process.env.STATIC_DIR + '/index.html');
  res.sendFile(path);
});

app.post("/create-cardholder", async (req, res) => {
    const { name } = req.body;

    try {

      const cardholder = await stripe.issuing.cardholders.create({
        type: 'individual',
        name,
        email: 'jenny.rosen@example.com',
        phone_number: '+18888675309',
        billing: {
          address: {
            line1: '1234 Main Street',
            city: 'San Francisco',
            state: 'CA',
            country: 'US',
            postal_code: '94111',
          },
        },
      });
      return res.redirect(`/new-card.html?cardholder=${cardholder.id}`);
    } catch (error) {
      return res.status(400).send({
        error: {
          message: error.message
        }
      });

    }
  })

app.get('/config', (req, res) => {
  res.send({
    publishableKey: process.env.STRIPE_PUBLISHABLE_KEY,
  });
});

// Expose a endpoint as a webhook handler for asynchronous events.
// Configure your webhook in the stripe developer dashboard
// https://dashboard.stripe.com/test/webhooks
app.post('/webhook', async (req, res) => {
  let data, eventType;

  // Check if webhook signing is configured.
  if (process.env.STRIPE_WEBHOOK_SECRET) {
    // Retrieve the event by verifying the signature using the raw body and secret.
    let event;
    let signature = req.headers['stripe-signature'];
    try {
      event = stripe.webhooks.constructEvent(
        req.rawBody,
        signature,
        process.env.STRIPE_WEBHOOK_SECRET
      );
    } catch (err) {
      console.log(`⚠️  Webhook signature verification failed.`);
      return res.sendStatus(400);
    }
    data = event.data;
    eventType = event.type;
  } else {
    // Webhook signing is recommended, but if the secret is not configured in `config.js`,
    // we can retrieve the event data directly from the request body.
    data = req.body.data;
    eventType = req.body.type;
  }

  if (eventType === 'payment_intent.succeeded') {
    // Funds have been captured
    // Fulfill any orders, e-mail receipts, etc
    // To cancel the payment after capture you will need to issue a Refund (https://stripe.com/docs/api/refunds)
    console.log('💰 Payment captured!');
  } else if (eventType === 'payment_intent.payment_failed') {
    console.log('❌ Payment failed.');
  }
  res.sendStatus(200);
});

app.listen(4242, () => console.log(`Node server listening at http://localhost:4242`));
raven oak
#

I don't need to see your whole code-

void pawn
#

ah okay

raven oak
#

What debugging steps have you taken so far? Have you pinpointed whether the issue is with your server? Is it being hit correctly? Are you seeing any logs?

void pawn
#

crbug/1173575, non-JS module files deprecated.

#

stripe-sample-demo@1.0.0 start
node server.js

Debugger attached.
Waiting for the debugger to disconnect...
node:internal/modules/cjs/loader:1078
throw err;
^

Error: Cannot find module 'express'
Require stack:

  • C:\Users\jay-t\Documents\stripe API\developer-office-hours\server\server.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)
    at Module._load (node:internal/modules/cjs/loader:920:27)
    at Module.require (node:internal/modules/cjs/loader:1141:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object.<anonymous> (C:\Users\jay-t\Documents\stripe API\developer-office-hours\server\server.js:1:17)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Module._load (node:internal/modules/cjs/loader:958:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
    code: 'MODULE_NOT_FOUND',
    requireStack: [
    'C:\Users\jay-t\Documents\stripe API\developer-office-hours\server\server.js'
    ]
    }

Node.js v18.16.0
Waiting for the debugger to disconnect...
PS C:\Users\jay-t\Documents\stripe API\developer-office-hours\server>

raven oak
#

Yeah, so it looks like you're missing some of the setup steps for that tutorial (you probably didn't install express correctly)

void pawn
#

ah okay ill look back on that

void pawn
#

TypeError: root path required
at Function.serveStatic [as static] (C:\Users\jay-t\Documents\stripe API\developer-office-hours\server\node_modules\serve-static\index.js:40:11)
at Object.<anonymous> (C:\Users\jay-t\Documents\stripe API\developer-office-hours\server\server.js:16:17)
at Module._compile (node:internal/modules/cjs/loader:1254:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
at Module.load (node:internal/modules/cjs/loader:1117:32)
at Module._load (node:internal/modules/cjs/loader:958:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47

Node.js v18.16.0
Waiting for the debugger to disconnect...
PS C:\Users\jay-t\Documents\stripe API\developer-office-hours\server>

raven oak
#

What do you get when you log process.env.STATIC_DIR