Capture Stripe Payment Intent - javascript

I am trying to capture a payment intent I have previously created. The payment intent has been set up and confirmed and I am now looking to complete the payment intent with the final amount and transfer the money to a stripe connect user.
const intent = await stripe.paymentIntents.capture({
id: paymentIntentId,
amount_to_capture: finalAmount,
transfer_data:{destination: connectedAccountId,},
});
The above code snippet is what I have so far, I know this is the correct method but I'm getting the following error:
Error: Stripe: Argument "intent" must be a string, but got: [object Object]
It must be to do with how I'm assigning the connect account id. reading the stripe api docs I need to pass the connect account id to the destination field of transfer data.
How should I be passing that in to the nested destination field. My syntax must be wrong.
Here is the stripe documentation for capturing a payment:
Stripe Capture Payment API Documentation
Any help is greatly appreciated.

Are you sure paymentIntentId is in fact an id as a string? From the error, it sounds like this might be a payment intent object and you'd need to use something like paymentIntent.id instead. (paymentIntentId.id as a quick correction, but you should rename the variable to represent its contents).
Double check the value of paymentIntentId -- it's probably different than you expect.
Update: This is due to a misreading of the syntax. The payment intent id is the first argument as a string, with the options in an object as a second argument. So then this is what you need:
const intent = await stripe.paymentIntents.capture(
paymentIntentId,
{
amount_to_capture: finalAmount,
transfer_data: { destination: connectedAccountId, },
}
);

Related

Can I generate a transaction on the server and send it to the client for payment

I have built a smart contract method to which I pass some sensitive data that needs to be stored on the blockchain and alter the state of the contract. I, the creator of the contract don't want to be the one paying for the fees of that transaction. I want the user on the browser to approve and pay for it.
However, I do not want to generate the transaction object on the browser as I want some of the data that will be passed to the contract to be hidden from the client. If I understand the web3 syntax correctly, in the code below, I'm doing just that
web3.eth.sendTransaction({
from: walletAddressOfTheUserThatWillPayForTheTransaction,
data: myContract.methods.changeState(..sensitive data...).encodeABI()
})
However I do not want the above to happen on the browser. In my head, the sequence of events should look like this (pseudocode):
// server
let transactionObject = {
from: walletAddressOfTheUserThatWillPayForTheTransaction,
data: myContract.methods.changeState(..sensitive data...).encodeABI()
}
sendToClient(encrypt(transactionObject))
// client
let encryptedTransactionObject = await fetchEncryptedTransactionObjectFromServer()
// this should open up Metamask for the user so that they may approve and finalise the transaction on the browser
web3.eth.sendTransaction(encryptedTransactionObject)
Is this possible ? Is there some other way of achieving this? Could you provide me with some hints about the actual syntax to be used?
However, I do not want to generate the transaction object on the browser as I want some of the data that will be passed to the contract to be hidden from the client.
Then you should not be using public blockchains in the first place, as all data on public blockchains, by definition, is public. Anyone can read it.

Discord JS - Reverse lookup to obtain userID from their display name

We're currently building a bot that will review specific messages and perform follow-up administrative actions on it. One of the actions will read a message and extract a named user (string - not link), search for it and return the ID of the user - which is then used elsewhere.
if (message.channel.id === register) {
// The post is in the register channel
if (message.content.includes('doing business with you')) {
//it's a successful claim
Rclaimedby = message.content.match(/\*\*(.*?)\*\*/)[1];
const Ruser = client.users.cache.find(user => user.username == Rclaimedby).id;
The text snippet will just have the individuals name as a string, which the regex will extract. If the individual doesn't have a nickname set, it'll work and the rest of the code works. However, as soon as that name isn't their "normal" name, it doesn't work and crashes with a TypeError.
I need to be able to use that stripped name and find the ID regardless of whether they have a nickname or not, but I've been searching for days (and a LOT of trial and error) and can't find a way around it.
To help, the message content would say something like:
(...) doing business with you normalname (...) or
(...) doing business with you randomnickname (...)
Help?
Like you mentioned in your comment, the key difference between extracting a user's ID from their displayName would mean you would have to get the GuildMember object first (it's server-specific) and then get the user property from that.
All in all, it just requires a little bit of re-maneuvering around the variables in order to get what you want since the displayName property is specific to each server.
Process:
Get the server ID
From the server ID, get the server
Get the members property from the server
Find the member by matching it with the given randomnickname, which I've set as displayNickname in this case.
Get the user property from the GuildMember object and grab the ID from there.
Code:
This is merely something you can work off of.
if (command === "memberinfo") {
let serverID = "800743801526157383"; //server id; manually input your own
let displayNickname = args[0];
message.channel.send(`Sent Nickname: ${displayNickname}`);
let serverMembers = client.guilds.cache.get(serverID).members //defines server and returns members
let matchedMember = serverMembers.cache.find(m => m.displayName === displayNickname);
message.channel.send(`Matched Member ${matchedMember.user.username}.`)
console.log(`The user's ID: ${matchedMember.user.id}`);
}
Resources:
SO Question - Fetching user from displayName
Discord.js Documentation

Create Stripe token without elements

I am trying to create a Stripe toke, but without elements.
This is my code:
stripe.createToken('person', {
card: '4242424242424242'
}, function(err, token) {
console.log(token)
// asynchronously called
});
The error in the console is:
Unrecognized token creation parameter parameter: card is not a recognized parameter. This may cause issues with your integration in the future.
The response error is:
You must supply either a card, customer, PII data, bank account, or account legal entity to create a token. If you're making this request with a library, be sure to pass all of the required parameters for creating a token. If you're making this request manually, be sure your POST parameters begin with the token type. For...
I can't find in the docs, which params, I must add.
You cannot create a token using a raw credit card in the current version of Stripe's APIs. You must use an element. While this is not explicitly stated in the createToken documentation, there is a notice in the createSource docs:
You cannot pass raw card information to stripe.createSource(sourceData). Instead, you must gather card information in an Element and use stripe.createSource(element, sourceData). You can also pass an existing card token to convert it into a Source object.
If you absolutely do not want to create an element, you could use the deprecated Stripe.card.createToken v2 API, but this is not recommended.

Parse Query Include method not including all data expected

I am doing a query onto a class where I have a pointer to a User.
I do query.include('byUser') and when I log out the query result it's shown but when I try to get a specific attribute like email. It doesnt exist.
I also first thought it was odd that I have to get the User details by doing:
const userDetails = query.get("byUser").attributes;
Do I have to do .attributes? And also why isn't the email showing up. Everything else seems to show up in the attributes section.
Thanks
Please note that in parse, you can not query the email field of other users. you can see the email field only if you are the signed in user. This is a security mechanism.
A. If you want to get the email field for a user object, you can do two things:
Pass the user session token to the query.
new Parse.Query(Parse.User).get(<userId>,{sessionToken:<userSessionToken>});
Use master key. (Note: You have to set the master key before.)
new Parse.Query(Parse.User).find({useMasterKey:true});
B. Your include method is correct and it it will fetch the byUser object. You do not need to use .attributes.
UPDATE:
You can also set a publicEmail field in your User class which will not be filtered out by parse-server. to automate this, you can write a cloud code.
Cloud Code Example (on parse-server V 3.0.0 and above):
PLEASE NOTE THAT YOU CAN NOT USE ASYNC FUNCTIONS FOR PARSE-SERVER < V 3.0.0
Parse.Cloud.beforeSave(Parse.User, async req=>{
if (!req.original && !req.master && req.object.get('email')){
req.object.set('publicEmail',req.object.get('email'));
}
})
Now, if new user sign up, this cloud code will automatically adds a new field to the user object publicEmail which is not filtered by parse-server.

Yodlee REST API - error adding new user "Exception Occurred"

I am trying to use the Yodlee REST API to access our Private Zone and add a new user. I am using the register3 api which I'm calling at
https://sdkint11.yodlee.com/yodsoap/srest/private-XXX/v1.0/jsonsdk/UserRegistration/register3
The dummy user credentials are as follows:
{ cobSessionToken: '10072014_0:58f1876ccc25848a712fade98d9d31c067cb5b4d322094845b4f8359ee59dc2ba01f1e94cfc9d5bd116d32ff6333f84fd848817b9b20cd9b1e85d50774a0ea32',
userCredentials:
{ loginName: 'AAAAAA',
password: 'BBBBBB',
objectInstanceType: 'com.yodlee.ext.login.PasswordCredentials' },
userProfile: { emailAddress: 'ABC#DEF.co.uk' } }
I've changed the credentials a bit for privacy, and for now I'm only using the 5 mandatory arguments required to establish a new user.
The (not very helpful) error I'm getting is
{"errorOccurred":"true","exceptionType":"Exception
Occurred","referenceCode":"_e37c33ab-b59c-4fbc-ab6a-1a2b83f5784f"}
which doesn't help debugging much.
Anyone any ideas?
You are passing the parameters in form of objects which will not be accepted by Yodlee. You will have to strictly follow the way it's represented in the document.
So your request parameter should look like for example -
cobSessionToken: '10072014_0:58f1876ccc220950774a0ea32',
userCredentials.loginName:'AAAAAA', userCredentials.password:'BBBBBB'
Please try out the suggested changes.

Categories

Resources