Getting error while making charges on connected Standalone Acount(Stripe) - stripe-payments

I'm trying to make charges on connected standalone acount. I'm using parse cloud code for that...it gives me following error:
Error Domain=Parse Code=141 "ReferenceError: stripe is not defined
Below is my code..
var Stripe = require('stripe');
Stripe.initialize('**************************');
Parse.Cloud.define("hello", function(request, response) {
var token = request.params.stripeToken;
var userid = request.params.userId;
stripe.charges.create(
{
amount: 1000,
currency: "usd",
source: token,
description: "Example charge",
application_fee: 123
},
{stripe_account: userid},{
success: function(httpResponse) {
response.success("Purchase made!");
},
error: function(httpResponse) {
response.error(error);
}
});
});

Related

Stripe Node JS integration no error callback

I've been trying to integrate Stripe with Node JS, but I can't get Stripe to return the error. I pass malformed data on purpose, but I still can not get the error back.
I'm new to Node JS.
Here is Stripe's official doc:
https://stripe.com/docs/api/charges/create
Here is my code:
Parse.Cloud.define("addCredit", (request) => {
// Use stripe API and your own 'secret key'
var stripe = require('stripe')('xdsewew');
// Charge user's card
stripe.charges.create({
amount: request.params.amount,
currency: 'usd',
source: request.params.token,
description: request.params.userId,
}, function(error, charge) {
return(error);
});
});
Maybe I'm not doing it right when I try to return the error?
I tried the same and I'm able to log the error
var stripe = require("stripe")("sk_test_4eC39HqLyjWDarjtT1zdp7d");
stripe.charges.create(
{
amount: 2000,
currency: "usd",
source: "tok_mastercard",
description: "My First Test Charge (created for API docs)",
},
function (err, charge) {
if (err) {
// different ways to log error
console.log("error message -> ", err.message);
console.log("error type - >", err.type);
console.log("eror raw -> ", err.raw);
return err;
}
console.log(charge);
}
);
Hope this works for you :)

Authentication error while implementing Stripe in Node js

I am trying to implement Stripe in my backend which is in node js. While calling it from front end I am getting this error:
You did not provide an API key, though you did set your Authorization header to "null". Using Bearer auth, your Authorization header should look something like 'Authorization: Bearer YOUR_SECRET_KEY'. See https://stripe.com/docs/api#authentication for details, or we can help at https://support.stripe.com/.
Here is my code:
const stripe = require("stripe")(process.env.keySecret);
if(req.body.type == 'stripe') {
const token = req.body.token;
const amount = req.body.amount;
let charge = stripe.charges.create({
amount: amount,
source: token,
currency: 'USD'
},(err, chargeData) => {
if(err) {
console.log('error in buy premium api error... ', err);
return;
}
let payment = [];
payment.push({
amount: chargeData.amount,
address: chargeData.billing_details.address,
email: chargeData.billing_details.email,
payment_method_details: chargeData.payment_method_details.card
})
console.log('charge... ', charge);
if(charge) {
register.findByIdAndUpdate({ _id: therapist._id },
{
$set:
{
payment_details: payment
}
}, {new:true}, (e1, updatedUser) => {
if(e1) {
return;
}
resolve(updatedUser);
})
}
})
}
else {
let err = 'No payment type define..';
return reject(err);
}
My req.body is:
{
"token": "tok_1F2XPBG04BYg8nGtLoWnQwRU", // coming from front end
"amount": "250",
"type":"stripe"
}
The secret key is test secret key which is like sk_test_xxxxxxxxxxxxxxxx.
My front end is in Angular 6 and from front end I am passing my test publishable key i.e. pk_test_xxxxxxxxxxxxxxxxx. I am passing proper data to the both front end as well as backend. Where am I mistaken?
Since you are calling .env file, you have to include the following line before requiring stripe:
require ("dotenv").config();
const stripe = require("stripe")(process.env.keySecret);

Invalid registration token provided. Make sure it matches the registration token the client app receives from registering with FCM

I got this code from my client iOS app on XCode console
Firebase registration token: diWY78iar8s:APA91bHJAzXe384OEYvfk4bKsyS1NQvteph7DwG7JRIMm_HuXg8EeNllVrsSi0v9W_Gh95ezbOStp3ZWuWl0AzFKxMaCOjN81yiz7A5qhkONrd7lP2CTkUbFErw28r3ONTLvo8c8sO7h
diWY78iar8s:APA91bHJAzXe384OEYvfk4bKsyS1NQvteph7DwG7JRIMm_HuXg8EeNllVrsSi0v9W_Gh95ezbOStp3ZWuWl0AzFKxMaCOjN81yiz7A5qhkONrd7lP2CTkUbFErw28r3ONTLvo8c8sO7h
NodeJS
console.log("START");
var FCM = require('fcm-node');
var serverKey = require('/Users/bheng/Desktop/Apps/APNS/node/mhn-app-firebase-adminsdk-bs45c-5ac3770488.json')
var fcm = new FCM(serverKey)
var collapseKey = 'new_message';
var message = {
to: 'diWY78iar8s:APA91bHJAzXe384OEYvfk4bKsyS1NQvteph7DwG7JRIMm_HuXg8EeNllVrsSi0v9W_Gh95ezbOStp3ZWuWl0AzFKxMaCOjN81yiz7A5qhkONrd7lP2CTkUbFErw28r3ONTLvo8c8sO7hdiWY78iar8s:APA91bHJAzXe384OEYvfk4bKsyS1NQvteph7DwG7JRIMm_HuXg8EeNllVrsSi0v9W_Gh95ezbOStp3ZWuWl0AzFKxMaCOjN81yiz7A5qhkONrd7lP2CTkUbFErw28r3ONTLvo8c8sO7h',
data: {
cpeMac: '000000000000',
type: 'malware'
},
notification: {
title: 'Hello baby',
body: 'Nice body',
tag: collapseKey,
icon: 'ic_notification',
color: '#18d821',
sound: 'default',
},
};
fcm.send(message, function(err, response){
if (err) {
console.log("Something has gone wrong!")
console.log(JSON.stringify(err));
} else {
console.log("Successfully sent with response: ", JSON.stringify(response))
}
})
console.log("END");
Result
When I run it
node app.js
I kept getting
START
END
Successfully sent with response: {"results":[{"error":{"code":"messaging/invalid-registration-token","message":"Invalid registration token provided. Make sure it matches the registration token the client app receives from registering with FCM."}}],"canonicalRegistrationTokenCount":0,"failureCount":1,"successCount":0,"multicastId":7577724855311354000}
How would one go about debugging this further?
your token has some additional random string such as
to: 'diWY78iar8s:APA91bHJAzXe384OEYvfk4bKsyS1NQvteph7DwG7JRIMm_HuXg8EeNllVrsSi0v9W_Gh95ezbOStp3ZWuWl0AzFKxMaCOjN81yiz7A5qhkONrd7lP2CTkUbFErw28r3ONTLvo8c8sO7hdiWY78iar8s:APA91bHJAzXe384OEYvfk4bKsyS1NQvteph7DwG7JRIMm_HuXg8EeNllVrsSi0v9W_Gh95ezbOStp3ZWuWl0AzFKxMaCOjN81yiz7A5qhkONrd7lP2CTkUbFErw28r3ONTLvo8c8sO7h',
just remove : diWY78iar8s: from your token string
console.log("START");
var FCM = require('fcm-node');
var serverKey = require('/Users/bheng/Desktop/Apps/APNS/node/mhn-app-firebase-adminsdk-bs45c-5ac3770488.json')
var fcm = new FCM(serverKey)
var collapseKey = 'new_message';
var message = {
to: 'APA91bHJAzXe384OEYvfk4bKsyS1NQvteph7DwG7JRIMm_HuXg8EeNllVrsSi0v9W_Gh95ezbOStp3ZWuWl0AzFKxMaCOjN81yiz7A5qhkONrd7lP2CTkUbFErw28r3ONTLvo8c8sO7hdiWY78iar8s:APA91bHJAzXe384OEYvfk4bKsyS1NQvteph7DwG7JRIMm_HuXg8EeNllVrsSi0v9W_Gh95ezbOStp3ZWuWl0AzFKxMaCOjN81yiz7A5qhkONrd7lP2CTkUbFErw28r3ONTLvo8c8sO7h',
data: {
cpeMac: '000000000000',
type: 'malware'
},
notification: {
title: 'Hello baby',
body: 'Nice body',
tag: collapseKey,
icon: 'ic_notification',
color: '#18d821',
sound: 'default',
},
};
fcm.send(message, function(err, response){
if (err) {
console.log("Something has gone wrong!")
console.log(JSON.stringify(err));
} else {
console.log("Successfully sent with response: ", JSON.stringify(response))
}
})
console.log("END");
Response from FCM :
Successfully sent with response: { results: [ { messageId: '0:1543448946734425%479ec0e2479ec0e2' } ],
canonicalRegistrationTokenCount: 0,
failureCount: 0,
successCount: 1,
multicastId: 6133765431734591000 }
One of the interesting reasons for invalid registration is: that device have a different token. Maybe you are trying to use a past token.
In my case what happened was I was getting the FCMRegistrationToken from my colleague via Discord and the Ctrl+C Ctrl+V was modifying the token. On obtaining the token via email solved the issue.

Stellar Node JS Payment Error

I'm working on a simple API, we are using this SDK but when we try on live with this script.
var StellarSdk = require('stellar-sdk');
StellarSdk.Network.usePublicNetwork();
var keypair = StellarSdk.Keypair.fromSecret('OUR SECRET');
var server = new StellarSdk.Server('https://horizon.stellar.org');
var sourceKeypair = StellarSdk.Keypair.random();
console.log(sourceKeypair.publicKey());
console.log(sourceKeypair.secret());
var secret = sourceKeypair.secret();
var public = sourceKeypair.publicKey();
server.loadAccount(keypair.publicKey())
.then(function(source) {
var transaction = new StellarSdk.TransactionBuilder(source)
.addOperation(StellarSdk.Operation.payment({
destination: public,
amount: "1",
asset: StellarSdk.Asset.native()
}))
.build();
transaction.sign(keypair);
return server.submitTransaction(transaction);
})
.then(function() {
return server.loadAccount(public)
})
.catch(function(error) {
console.error('Error!', error);
});
On the script we created a new account and we want to activate it with 1 lumen, the secret of the Payment have at least 1000 lumens, but when we make the transactions, it give this error:
Error! { [BadResponseError: Transaction submission failed. Server responded: 400 Bad Request]
name: 'BadResponseError',
message: 'Transaction submission failed. Server responded: 400 Bad Request',
data:
{ type: 'https://stellar.org/horizon-errors/transaction_failed',
title: 'Transaction Failed',
status: 400,
detail: 'The transaction failed when submitted to the stellar network. The `extras.result_codes` field on this response contains further details. Descriptions of each code can be found at: https://www.stellar.org/developers/learn/concepts/list-of-operations.html',
instance: 'horizon-001a/Fm1q5QnVH4-247091670',
extras:
{ envelope_xdr: 'AAAAACO0e3CpDcv7A+FzZkIdKI0Jqhln3kEwK3OsVJW6fOYMAAAAZADzojYAAAAaAAAAAAAAAAAAAAABAAAAAAAAAAEAAAAA90HkP1W5wCsFRAGGKE1z1b+b7PnetRAQI6/XIo9R2PwAAAAAAAAAAACYloAAAAAAAAAAAbp85gwAAABAr1tWwYjH5fjEUL6gsgFCrJbQakDuSk6bE2AYE51NAZkH4N6f7JCkwAEH2A1XSG334sprokpxy7lWcVPW92XgBw==',
result_codes: [Object],
result_xdr: 'AAAAAAAAAGT/////AAAAAQAAAAAAAAAB////+wAAAAA=' } } }
Any advice?

braintree + NodeJS gives an "authentication Error "

I'm trying to build a payment gateway library using braintree's NodeJS library, I'm making an ajax call from front end with the card data.
Client-Side
var card_data = {
type: "AmEx",
number: "3XXXXXXXXXXXXXX",
expire_month: "XX",
expire_year: "201X",
cvv2: "XXX",
name: "sandeep",
price : "200",
currency : "USD"
};
Ajax call,
$.ajax({
method: "GET",
url: "http://localhost:3000/paymentPath_braintree",
data: card_data
}).done(function(message){
console.log(message);
}).fail(function(data, message){
console.log(message);
});
Server-Side
var braintreePay = require('braintree');
app.get("/payment_braintree", function(request, response){
var data = request.query;
var gateway = braintreePay.connect({
environment: braintreePay.Environment.Sandbox,
merchantId: "MymerchentID",
publicKey: "MypublicKey",
privateKey: "MyprivateKey",
});
var saleRequest = {
amount: data.price,
creditCard: {
number: data.number,
cvv: data.cvv2,
expirationMonth: data.expire_month,
expirationYear: data.expire_year.slice(2),
cardHolder: data.name
},
options: {
submitForSettlement: true
}
};
gateway.transaction.sale(saleRequest, function(error, result){
if(error){
console.log(error.name);
throw error;
}
if(result.success){
response.send(result.transaction.id);
} else {
response.send(result.message);
}
});
});
I have cross checked everything, from keys and card data everything is in order but i am getting an error in callback after making gateway.transaction.sale(...); called Authentication Error . Which i tried to figure out for hours but could not get through.
error object is
authenticationError: Authentication Error
arguments: undefined
message: "Authentication Error"
name: "authenticationError"
stack: undefined
type: "authenticationError"
Where am i going wrong?
I have created an account sandbox.braintreegateway those key credentials are from the account that i have created, i din't create an app like how its done in paypal.
I am going through lack of understanding in Braintree integration.
Are their any proper documented resource.

Resources