Unable to import module 'charge': Error : netlify functions
i did this gatsby and netlify.
https://www.thedigitalsages.com/creating-charges-for-stripe-with-react-and-netlify-functions-part-1/
but but I am getting this error.
Unable to import module 'charge': Error
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/var/task/charge.js:1:76)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
checkoutForm.js
import React from 'react';
import {injectStripe} from 'react-stripe-elements';
import axios from 'axios';
import AddressSection from './AddressSection';
import CardSection from './CardSection';
import {Button} from 'reactstrap';
import Success from './Success';
import './form-css.css'
class CheckoutForm extends React.Component {
constructor(props) {
super(props);
this.state = {
name: undefined,
email: undefined,
address: undefined,
city: undefined,
state: undefined,
program: undefined,
price: undefined,
success: false
};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
const name = event.target.name
this.setState({[name]: event.target.value});
}
handleSubmit = (ev) => {
ev.preventDefault();
this.props.stripe.createToken({
name: this.state.name,
address_city: this.state.city,
address_line1: this.state.address,
address_state: this.state.state,
address_country: "US"
}).then(({token}) =>
{
const charge = JSON.stringify({
token,
charge: {
amount: 2000,
currency: 'usd',
email: this.state.email,
number: this.state.number
},
})
axios.post('/.netlify/functions/charge', charge)
.catch(function (error) {
console.log(error);
})
});
};
render() {
return (
<form onSubmit={this.handleSubmit} id="form-css" className="w-100">
{ this.state.success === false ?
<div>
<AddressSection handleChange={this.handleChange} schedule={this.state.schedule} />
<CardSection />
</div>
:
<Success />
}
<Button className="w-100 h4">Pay $50</Button>
</form>
);
}
}
export default injectStripe(CheckoutForm);
charge.js folder / function/charge.js and working on netlify function.
var stripe = require("stripe")("....");
var axios = require('axios');
module.exports.handler = (event, context, callback) => {
const requestBody = JSON.parse(event.body);
const token = requestBody.token.id;
const amount = requestBody.charge.amount;
const currency = requestBody.charge.currency;
const email = requestBody.charge.email;
return stripe.charges.create({ // Create Stripe charge with token
amount,
currency,
receipt_email: email,
description: 'Serverless Stripe Test charge',
source: token,
})
.then((charge) => { // Success response
const response = {
statusCode: 200,
body: JSON.stringify({
message: `Charge processed succesfully!`,
charge,
}),
};
callback(null, response);
})
.catch((err) => { // Error response
const response = {
statusCode: 500,
body: JSON.stringify({
error: err.message,
}),
};
callback(null, response);
})
};
i think axios errors /:
https://reverent-meitner-8da20d.netlify.com/ demo link thanks.
javascript reactjs gatsby
add a comment |
i did this gatsby and netlify.
https://www.thedigitalsages.com/creating-charges-for-stripe-with-react-and-netlify-functions-part-1/
but but I am getting this error.
Unable to import module 'charge': Error
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/var/task/charge.js:1:76)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
checkoutForm.js
import React from 'react';
import {injectStripe} from 'react-stripe-elements';
import axios from 'axios';
import AddressSection from './AddressSection';
import CardSection from './CardSection';
import {Button} from 'reactstrap';
import Success from './Success';
import './form-css.css'
class CheckoutForm extends React.Component {
constructor(props) {
super(props);
this.state = {
name: undefined,
email: undefined,
address: undefined,
city: undefined,
state: undefined,
program: undefined,
price: undefined,
success: false
};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
const name = event.target.name
this.setState({[name]: event.target.value});
}
handleSubmit = (ev) => {
ev.preventDefault();
this.props.stripe.createToken({
name: this.state.name,
address_city: this.state.city,
address_line1: this.state.address,
address_state: this.state.state,
address_country: "US"
}).then(({token}) =>
{
const charge = JSON.stringify({
token,
charge: {
amount: 2000,
currency: 'usd',
email: this.state.email,
number: this.state.number
},
})
axios.post('/.netlify/functions/charge', charge)
.catch(function (error) {
console.log(error);
})
});
};
render() {
return (
<form onSubmit={this.handleSubmit} id="form-css" className="w-100">
{ this.state.success === false ?
<div>
<AddressSection handleChange={this.handleChange} schedule={this.state.schedule} />
<CardSection />
</div>
:
<Success />
}
<Button className="w-100 h4">Pay $50</Button>
</form>
);
}
}
export default injectStripe(CheckoutForm);
charge.js folder / function/charge.js and working on netlify function.
var stripe = require("stripe")("....");
var axios = require('axios');
module.exports.handler = (event, context, callback) => {
const requestBody = JSON.parse(event.body);
const token = requestBody.token.id;
const amount = requestBody.charge.amount;
const currency = requestBody.charge.currency;
const email = requestBody.charge.email;
return stripe.charges.create({ // Create Stripe charge with token
amount,
currency,
receipt_email: email,
description: 'Serverless Stripe Test charge',
source: token,
})
.then((charge) => { // Success response
const response = {
statusCode: 200,
body: JSON.stringify({
message: `Charge processed succesfully!`,
charge,
}),
};
callback(null, response);
})
.catch((err) => { // Error response
const response = {
statusCode: 500,
body: JSON.stringify({
error: err.message,
}),
};
callback(null, response);
})
};
i think axios errors /:
https://reverent-meitner-8da20d.netlify.com/ demo link thanks.
javascript reactjs gatsby
add a comment |
i did this gatsby and netlify.
https://www.thedigitalsages.com/creating-charges-for-stripe-with-react-and-netlify-functions-part-1/
but but I am getting this error.
Unable to import module 'charge': Error
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/var/task/charge.js:1:76)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
checkoutForm.js
import React from 'react';
import {injectStripe} from 'react-stripe-elements';
import axios from 'axios';
import AddressSection from './AddressSection';
import CardSection from './CardSection';
import {Button} from 'reactstrap';
import Success from './Success';
import './form-css.css'
class CheckoutForm extends React.Component {
constructor(props) {
super(props);
this.state = {
name: undefined,
email: undefined,
address: undefined,
city: undefined,
state: undefined,
program: undefined,
price: undefined,
success: false
};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
const name = event.target.name
this.setState({[name]: event.target.value});
}
handleSubmit = (ev) => {
ev.preventDefault();
this.props.stripe.createToken({
name: this.state.name,
address_city: this.state.city,
address_line1: this.state.address,
address_state: this.state.state,
address_country: "US"
}).then(({token}) =>
{
const charge = JSON.stringify({
token,
charge: {
amount: 2000,
currency: 'usd',
email: this.state.email,
number: this.state.number
},
})
axios.post('/.netlify/functions/charge', charge)
.catch(function (error) {
console.log(error);
})
});
};
render() {
return (
<form onSubmit={this.handleSubmit} id="form-css" className="w-100">
{ this.state.success === false ?
<div>
<AddressSection handleChange={this.handleChange} schedule={this.state.schedule} />
<CardSection />
</div>
:
<Success />
}
<Button className="w-100 h4">Pay $50</Button>
</form>
);
}
}
export default injectStripe(CheckoutForm);
charge.js folder / function/charge.js and working on netlify function.
var stripe = require("stripe")("....");
var axios = require('axios');
module.exports.handler = (event, context, callback) => {
const requestBody = JSON.parse(event.body);
const token = requestBody.token.id;
const amount = requestBody.charge.amount;
const currency = requestBody.charge.currency;
const email = requestBody.charge.email;
return stripe.charges.create({ // Create Stripe charge with token
amount,
currency,
receipt_email: email,
description: 'Serverless Stripe Test charge',
source: token,
})
.then((charge) => { // Success response
const response = {
statusCode: 200,
body: JSON.stringify({
message: `Charge processed succesfully!`,
charge,
}),
};
callback(null, response);
})
.catch((err) => { // Error response
const response = {
statusCode: 500,
body: JSON.stringify({
error: err.message,
}),
};
callback(null, response);
})
};
i think axios errors /:
https://reverent-meitner-8da20d.netlify.com/ demo link thanks.
javascript reactjs gatsby
i did this gatsby and netlify.
https://www.thedigitalsages.com/creating-charges-for-stripe-with-react-and-netlify-functions-part-1/
but but I am getting this error.
Unable to import module 'charge': Error
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/var/task/charge.js:1:76)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
checkoutForm.js
import React from 'react';
import {injectStripe} from 'react-stripe-elements';
import axios from 'axios';
import AddressSection from './AddressSection';
import CardSection from './CardSection';
import {Button} from 'reactstrap';
import Success from './Success';
import './form-css.css'
class CheckoutForm extends React.Component {
constructor(props) {
super(props);
this.state = {
name: undefined,
email: undefined,
address: undefined,
city: undefined,
state: undefined,
program: undefined,
price: undefined,
success: false
};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
const name = event.target.name
this.setState({[name]: event.target.value});
}
handleSubmit = (ev) => {
ev.preventDefault();
this.props.stripe.createToken({
name: this.state.name,
address_city: this.state.city,
address_line1: this.state.address,
address_state: this.state.state,
address_country: "US"
}).then(({token}) =>
{
const charge = JSON.stringify({
token,
charge: {
amount: 2000,
currency: 'usd',
email: this.state.email,
number: this.state.number
},
})
axios.post('/.netlify/functions/charge', charge)
.catch(function (error) {
console.log(error);
})
});
};
render() {
return (
<form onSubmit={this.handleSubmit} id="form-css" className="w-100">
{ this.state.success === false ?
<div>
<AddressSection handleChange={this.handleChange} schedule={this.state.schedule} />
<CardSection />
</div>
:
<Success />
}
<Button className="w-100 h4">Pay $50</Button>
</form>
);
}
}
export default injectStripe(CheckoutForm);
charge.js folder / function/charge.js and working on netlify function.
var stripe = require("stripe")("....");
var axios = require('axios');
module.exports.handler = (event, context, callback) => {
const requestBody = JSON.parse(event.body);
const token = requestBody.token.id;
const amount = requestBody.charge.amount;
const currency = requestBody.charge.currency;
const email = requestBody.charge.email;
return stripe.charges.create({ // Create Stripe charge with token
amount,
currency,
receipt_email: email,
description: 'Serverless Stripe Test charge',
source: token,
})
.then((charge) => { // Success response
const response = {
statusCode: 200,
body: JSON.stringify({
message: `Charge processed succesfully!`,
charge,
}),
};
callback(null, response);
})
.catch((err) => { // Error response
const response = {
statusCode: 500,
body: JSON.stringify({
error: err.message,
}),
};
callback(null, response);
})
};
i think axios errors /:
https://reverent-meitner-8da20d.netlify.com/ demo link thanks.
javascript reactjs gatsby
javascript reactjs gatsby
edited Nov 24 '18 at 19:37
cnsvnc
asked Nov 24 '18 at 1:44
cnsvnccnsvnc
237111
237111
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53454491%2funable-to-import-module-charge-error-netlify-functions%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53454491%2funable-to-import-module-charge-error-netlify-functions%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown