Can't post variables to Parse JS API - javascript

I'm trying to make a sample page where I can fill in some forms and then save the data to Parse API. I tried this using strings first, like this:
var Billing = Parse.Object.extend("Billing");
var billing = new Billing();
billing.set("First Name", "John");
billing.set("Last Name", "Doe");
billing.set("Email", "admin#parse.com");
That did work fine, but when I just wrote a variable, I get an error "POST 400 Bad Request" :
var Billing = Parse.Object.extend("Billing");
var billing = new Billing();
billing.set("First Name", frnm);
billing.set("Last Name", lsnm);
billing.set("Email", eml);
Why is that? I can't seem to find another way to make it work...
See my full coded gist here here

I used:
document.getElementById("card_cvNumber").value;
Instead of:
$('#card_cvNumber').val();
And the Parse JS:
var Billing = Parse.Object.extend("Billing");
var billing = new Billing();
billing.save({Firstname: frnm, Lastname: lsnm, Company: cpnm, Adress: str1, City: cty, State: stat, PostalCode: zpc, Country: ctry, Phone: phn, Fax: fx, Email: eml}, {
success: function(object) {
alert("Success");
}
});
It worked just great!

Related

WooCommerce Nodejs Wrapper returns undefined

I am learning to work with the WooCommerce API and I am trying to modify the payment address and the shipping address of a user, but I get this error all the time and I do not understand what I am doing wrong.
The error:
TypeError: undefined is not a function
This is my code:
var WooCommerceAPI = require("woocommerce-api");
var api = new WooCommerceAPI({
url: 'https://site.es/',
consumerKey: 'ck_xxxx',
consumerSecret: 'cs_xxxx',
wpAPI: true,
version: 'wc/v3'
});
const data = {
first_name: "James",
billing: {
first_name: "James",
postcode: "99502",
},
shipping: {
first_name: "James",
postcode: "99502",
}
};
api.putAsync('customers/33', data).then(function(result) {
console.log(result);
});
I would really appreciate any help, because really, I don't know what's wrong. I have read a lot about this and I don't see the error.
Regards.
You are using an outdated version of the library. Use the following one in which all the methods are promisified by default - so, you don't have to perpend "Async" any more.
https://github.com/woocommerce/woocommerce-rest-api-js-lib
const WooCommerceRestApi = require("#woocommerce/woocommerce-rest-api").default;
const api = new WooCommerceRestApi({
url: "http://example.com",
consumerKey: "ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
consumerSecret: "cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
version: "wc/v3"
});
api.put("customers/33", data)
.then((response) => {
...

Create User API Mysql auto-increment bug

I am trying to get a simple create user function running, but keep getting a strange sql error which I am assuming comes from some sort of error around my use of the auto-increment key for mysql, but have been unable to identify the actual issue.
Below is an example of my server code:
app.post('/createPhysician', function(req, res) {
console.log(req.body);
// do input checking here
var createPromise = interact.createPhysician(req.body.physicianID,
req.body.firstName,
req.body.lastName,
req.body.yearNum,
req.body.position,
req.body.isAttending,
req.body.highRiskTrained)
//did promise
createPromise.then(function(createResponse) {
res.status(200).json({"status":"success"}); // .end because we just want to return an empty response
}).catch(function(err) {
console.log(err);
res.status(500).json(err);
});
});
Below is the interact.sql code for the func:
createPhysician: function(
firstName,
lastName,
yearNum,
position,
isAttending,
highRiskTrained) {
var qry = "insert into Physician (firstName, lastName, yearNum, position, isAttending, highRiskTrained) values \
('"+firstName+"', '"+lastName+"', "+yearNum+", '"+position+"', "+isAttending+", "+highRiskTrained+");";
return runQuery(qry);
}
Below is description of my mysql table:
Below is what I am entering for a body into Postman:
{
"firstName": "firstName",
"lastName": "lastName",
"yearNum": 1,
"position": "coder",
"isAttending": 1,
"highRiskTrained": 0
}
Below is the error that I get in Postman from the request:
{
"code": "ER_BAD_FIELD_ERROR",
"errno": 1054,
"sqlMessage": "Unknown column 'coder' in 'field list'",
"sqlState": "42S22",
"index": 0,
"sql": "insert into Physician (firstName, lastName, yearNum, position, isAttending, highRiskTrained) values ('undefined', 'firstName', lastName, '1', coder, 1);"
}
The output of the API console log for the request body is below:
{ firstName: 'firstName',
lastName: 'lastName',
yearNum: 1,
position: 'coder',
isAttending: 1,
highRiskTrained: 0 }
When wrapping a query with a function, make sure the proper parameters are used by the query AND passed into the function into the correctly.
It always feels a little weird putting a formal answer to what ends up being little more than a typo, but I suppose you never know who might need the same kind of typo pointed out.

Binding Separate Groups of JSON Data to a UserID Number AngularJS

I've been having trouble figuring out how to keep data as separate forms, but binding together inside of angularJS. This is for educational and testing purposes so I don't need to worry about setting this data to a db or using any type of storage for now other than the apps session and localstorage. For the test I will hard code into my JS.
I'm uploading a photo to showcase my thoughts and I'll explain it as well:
So my main data is a customers group. I have it set to iterate through and display using ng-repeat. No big worries there. I can add, and update each of these. When I had the proposals attached to the customers json object then when I edited the user, it would delete those proposals and quotes. So I want to keep them separate, but allow them to be called into the DOM by specific user.
My Problem:
Is that I do not know how to bind objects, to objects, and have them update in the dom anytime another action happens. Here is a pen of what I have so far
http://codepen.io/ddavisgraphics/pen/pvRZOv?editors=101.
Example of the Code Data:
var customerArray = [
// Start Customer
//--------------
{
customerID:1,
customer: 'Joe Frankelton',
phone: 1244957323,
email: 'jFrank#gmail.com',
// start address
address: {
line1:'248 Gallows Rd',
city:'Hangtown',
state:'West HangState',
zip:24750
},
}, // End Customer
// Start Customer
//--------------
{
customerID:2,
customer: 'Danny Manny',
phone: 1245423323,
email: 'dman#gmail.com',
// start address
address: {
line1:'253 Cow Run Rd',
city:'Beeftown',
state:'PA',
zip:24750
},
}, // End Customer
];
var proposals = [
{ // Proposal 1
customerID: 1,
projectTitle: 'Gameify Me Captin',
type: 'GameDesign',
deadline: 'Jan. 2, 2015',
deliveryType: 'Files',
problem: 'The problem is that the customer wants to much crap.',
notes: 'clients mother wants to be involved because she designed a peice of toast in 1973',
},
{ // Proposal 2
customerID: 2,
projectTitle: 'Playing',
type: 'Website',
deadline: 'Jan. 2, 2017',
deliveryType: 'Sites',
problem: 'Everything',
notes: 'client will be easy to work with, wants pink and blue',
},
];
var quotes = [
{
customerID: 2,
quoteNum: 2,
projectTitle: 'Project Title',
type: 'Graphic Design',
deadline: 'Jan. 2, 2015',
billableHrs: 11,
hourlyRate: 42.50,
externalCost: 33.99,
tax: 0.6,
}
];
What you can do is to create a viewmodel for customer by mapping the data from multiple sources, i.e customers, proposals and quotes.
You can use customerID to do the linking, example:
customer.proposals = proposals.filter(function(prop){
return prop.customerID === custId;
});
So you would do:
function getMappedCustomer() {
return customerArray.map(function(customer){
var custId = customer.customerID;
customer.proposals = proposals.filter(function(prop){ return prop.customerID === custId;});
customer.quotes = quotes.filter(function(quot){ return quot.customerID === custId; });
return customer;
});
}
// Init current data
$scope.customers = getMappedCustomer();
Similarly do it when you do the maping of updated customer. If you want to preserve customerArray use angular.copy(customerArray) and do the mapping on it.
Demo

how do i parse json value and get id into variable

hello i am having this code of jquery:
var fbuid = zuck;
var fbjson = $.getJSON("https://graph.facebook.com/"+fbuid);
how to get the id from json directly into var :
{
id: "4",
first_name: "Mark",
gender: "male",
last_name: "Zuckerberg",
link: "https://www.facebook.com/zuck",
locale: "en_US",
name: "Mark Zuckerberg",
username: "zuck"
}
all i would like to get id from json to var as below:
var fbjson.id;
how i do it using jquery?
So you're close but you've got some things you need to adjust. Ajax is async which means that you're waiting on a server response. You need to fill your data once you have that piece of data. Note you will not be able to reference fbjson until AFTER the getJSON has fired and completed.
According to the jQuery documentation for getJSON
you need to have a callback similar to this -
var fbuid = 'zuck';
var fbjson;
$.getJSON( "https://graph.facebook.com/"+fbuid, function( data ) {
fbjson = data;
});
Notice I assign the fbjson in the callback to data which is the server response. now you can reference it as
fbjson.id

Stripe - Not charging card

I've setup a stripe custom checkout using javascript. Every parameter goes through, I receive a status 200 in the log when we make a payment. Everything looks like it goes through. However the amount remains as "0" in the Parsed Request Query Parameters and not charging the card.
I've gone over documentation for hours and can't get my head around the issue.
<script src="https://checkout.stripe.com/checkout.js"></script>
<script>
var pinId = "<%= #id %>";
var from = "<%= #from %>";
var content = "Supersize+me";
var handler = StripeCheckout.configure({
key: 'Published-Key',
image: '/assets/campusboard-logo.png',
token: function(token, args) {
$.getJSON( "purchased/"+pinId )
.done(function( data ) {
window.location = "http://"+window.location.host+"/pins/"+pinId+"?utm_source=Purchased&utm_medium="+from+"&utm_campaign=Featured%20Pins&utm_content="+content;
})
.fail(function( jqxhr, textStatus, error ) {
alert("We've encountered a problem with the transaction. Please try again.");
});
}
});
document.getElementById('ssm').addEventListener('click', function(e) {
// Open Checkout with further options
handler.open({
name: 'CampusBoard',
description: 'Featured Pin (£29.00)',
amount: "100",
currency: 'GBP',
panelLabel: 'Supersize my Pin'
});
e.preventDefault();
});
document.getElementById('mmh').addEventListener('click', function(e) {
// Open Checkout with further options
handler.open({
name: 'CampusBoard',
description: 'Featured Pin (£59.00)',
amount: 5900,
currency: 'GBP',
panelLabel: 'Make my Pin Huge'
});
content = "Make+me+huge";
e.preventDefault();
});
</script>
Can someone see where I'm going wrong?
Stripe Checkout is just a well-done pre-made payment form. You actually have to create a Charge object on your server using your Stripe secret API key. Follow these tutorials for your specific language.
You are passing the amount as a string whereas I think stripe is expecting it as a number. So:
handler.open({
...
amount: 100,
...
});

Categories

Resources