Pass CVC to stripe.createPaymentMethod JS? - stripe-payments

I need a separate input for CVC and Expiry, so I have created 3 Stripe Elements:
let elements = stripe.elements();
let cardNumber = elements.create('cardNumber');
cardNumber.mount('#card-number');
let cardExpiry = elements.create('cardExpiry');
cardExpiry.mount('#card-expiry');
let cardCvc = elements.create('cardCvc');
cardCvc.mount('#card-cvc');
...
Stripe Docs only mention about how to pass card or cardNumber Element to PaymentMethod, but how do I pass cardExpiry and cardCvc?
function paymentMethod() {
return stripe.createPaymentMethod({
type: 'card',
card: cardNumber,
billing_details: {
name: userName,
email: userEmail,
},
}).then(function(result) {
// code
});
}
Stripe Docs only mention that

Stripe.js methods automatically use all the different elements on your page under the hood, so you don't need to pass CVC and Expiry elements manually, createPaymentMethod will do that automatically under the hood for you.

Related

How to add a where clause dynamically to query which is generated using nestjs Query Builder?

I am working on an API for which the requirement from UI is based on the value of the search field I shall receive the filtered results. There are many search fields on UI.
Example code -
async getRoomsByMember(active: boolean, email: string): Promise<any[]> {
return await getRepository(Room)
.createQueryBuilder('room')
.innerJoinAndSelect('room.member', 'member')
.where("room.active = :active", {active: active})
.andWhere("member.email = :email", { email: email })
.getMany();
}
I shall be able to filter room members dynamically if values entered by a user on filter fields like - member phone number, city, state, country, and zip.
You're almost there :-)
You can try something like this:
async getRoomsByMember(active: boolean, email: string): Promise<any[]> {
const query = getRepository(Room)
.createQueryBuilder('room')
.innerJoinAndSelect('room.member', 'member')
.where("room.active = :active", {active: active});
// Keep adding your other fields like member phone number, city, state, country, and zip, like below
if(email) {
query.andWhere("member.email = :email", { email: email })
}
return query.getMany();
}

How do I select specific column data to be displayed in my bookshelf model belongsTo relationship in Nodejs?

This is a contrived example of what I would like to do:
Suppose I have a database of teams and players:
team:
->id
->color
->rank
->division
player:
->id
->team_id
->number
->SECRET
And the following bookshelf models:
var Base = require('./base');
const Player = Base.Model.extend(
{
tableName: "players",
},
nonsecretdata: function() {
return this.belongsTo('Team')
},
{
fields: {
id: Base.Model.types.integer,
team_id: Base.Model.types.integer,
number: Base.Model.types.integer,
SECRET: Base.Model.types.string,
}
}
);
module.exports = Base.model('Player', Player);
And
var Base = require('./base');
const Team = Base.Model.extend(
{
tableName: "teams",
},
{
fields: {
id: Base.Model.types.integer,
color: Base.Model.types.string,
rank: Base.Model.types.integer,
division: Base.Model.types.string,
}
}
);
module.exports = Base.model('Team', Team);
My question is, how can I limit the scope of player such that SECRET is not grabbed by calls to join player and team with callback nonsecretdata?
I am new to Bookshelf so if any other information is needed, please let me know. Thank you
++++++++++
Edit: Do I need to create a separate model?
The only way to do this using bookshelf would be to delete the individual fields from the object after fetching the entire model.
A potentially better solution for this use case would be to define a custom Data Access Object class that uses a SQL query for the information that would like to be obtained and then use that DOA instead of using bookshelf. That way the SQL code is still abstracted away from the code that is requesting the information and the SECRET or any other potential sensitive information that is added to the table will not be included in the fetch.

await account.save() isnt a function when i am trying to save after pushing an object inside wallets array

const account = await find.wallets.push({ id: message.author.id, amount: 0, date: message.createdAt})
await account.save();
it says, account.save() isn't a function
its working in other commands, when creating new doc
do i need to save when we push an object inside an array?
https://sourceb.in/634a9b2be0 - full code
well, account.save works in my command file in another subcommand = open
its actually creating a new doc
const account = new Account(..) (account is defined as the schema/model)
await account.save() works there
but its not working when i am trying to save it after using the array.push function
This const account = [...find.wallets, { id: message.author.id, amount: 0, date: message.createdAt}] is nonsense. It should be find.wallets.push({ id: message.author.id, amount: 0, date: message.createdAt}) no need to assign it to account
Molda has solved my question, thanks

Stripe - how call confirmCardSetup without cardElement?

I'm using my own form for the credit card creedentials.
I was trying to follow the instructions here https://laravel.com/docs/7.x/billing#storing-payment-methods
Based on the Stripe's instructions, you can pass cardElement or Card object. I would like to create the Card object myself, but I can't find which info does that object have:
cardButton.addEventListener('click', async (e) => {
const { setupIntent, error } = await stripe.confirmCardSetup(
clientSecret, {
payment_method: {
card: cardElement, //or Card object
billing_details: { name: cardHolderName.value }
}
}
);
if (error) {
// Display "error.message" to the user...
} else {
// The card has been verified successfully...
}
});
Not clear if I should simply use specific ids in my inputs, and then simply pass the form there, but I can't find that information.
You can see the details of the Card object here, which looks like this:
card: {
number: '4242424242424242',
exp_year: '2024',
exp_month: '02',
cvc: '123',
}
However, using Elements is strongly recommended.
It's important to be aware of the PCI compliance implications of this. It is your responsibility to make sure your implementation is compliant, and you will be required to provide additional documentation for your business.

How to customize the payment method in payment intent example in stripe

I am trying to follow the example shown in the following link https://stripe.com/docs/payments/accept-a-payment.
I have the following code in the client side
var cardNumber = elements.create('cardNumber', {
placeholder:'',
style: style
});
var cardexpiry = elements.create('cardExpiry',{
placeholder:'',
style:style
});
var cardCVV = elements.create('cardCvc',{
placeholder:'',
style:style
});
// Add an instance of the card Element into the `card-element` <div>.
cardNumber.mount('#card-element');
cardexpiry.mount("#card-expiry")
cardCVV.mount("#card-cvv")
instead of this
var card = elements.create("card", { style: style });
card.mount("#card-element");
Because the I wanted to some UI manipulation. According to the code posted in the link
I should do the following
var submitButton = document.getElementById('submit');
submitButton.addEventListener('click', function(ev) {
stripe.confirmCardPayment(clientSecret, {
payment_method: {card: card}
}).then(function(result) {
if (result.error) {
// Show error to your customer (e.g., insufficient funds)
console.log(result.error.message);
} else {
// The payment has been processed!
if (result.paymentIntent.status === 'succeeded') {
// Show a success message to your customer
// There's a risk of the customer closing the window before callback
// execution. Set up a webhook or plugin to listen for the
// payment_intent.succeeded event that handles any business critical
// post-payment actions.
}
}
});
});
However in the example above in the payment_method the card object is passed, which is not the case in my code. How can I pass my card number and exp/date as well CVC separately in the stripe.confirmCardPayment(clientSecret, {
payment_method: {card: card}
There was a similar question about how to call stripe.createToken() when you aren't using a card element.
According to the Stripe documentation for createToken:
The cardNumber Element you wish to tokenize data from. If applicable, the Element pulls data from other elements you’ve created on the same instance of Elements to tokenize—you only need to supply one Element as the parameter.
Now, for this case in particular, the section for confirmCardPayment says:
Use stripe.confirmCardPayment with payment data from an Element by passing a card or cardNumber Element as payment_method[card] in the data argument.
Basically you just have to pass the cardNumber element to payment_method["card"] and it will pull the data from the other elements you’ve created.
...
stripe.confirmCardPayment(clientSecret, {
payment_method: {card: cardNumber}
})
...
I ended up using this code
var stripe = Stripe('#YOUR KEY');
var elements = stripe.elements();
/// STYLE HERE
var style = {
base: {
fontSize: '16px',
color: "#32325d",
'::placeholder': {
color: '#CFD7E0',
fontSize: '12px'
}
}
};
// Create an instance of the card Element.
var card = elements.create('card', {
hidePostalCode: true,
placeholder: '',
style: style,
});
card.mount('#card-element');
card.addEventListener('change', function (event) {
var displayError = document.getElementById('card-errors');
if (event.error) {
displayError.textContent = '';
} else {
displayError.textContent = '';
}
});

Resources