Unable to get discount details in shopify from my application - javascript

I am writing a shopify application using node platform, I am trying to get discount info in shopify from my application using the npm module "shopify-node-api", it shows "404- Not Found" error, but, I am able to get products and custom_collections by this method.
var Shopify = require('shopify-node-api');
var config = {};
config.shop = myshop.myshopify.com;
config.shopify_api_key = XXXX;
config.shopify_shared_secret = XXXX;
config.access_token = XXXX;
sails.log.verbose('Shopify config object: ', config);
var shopify = new Shopify(config);
shopify.get('/admin/discounts.json', function(err, data)
if (err) {
sails.log.error("Error in getDiscount ", err);
} else {
sails.log.verbose(" shopify.getDiscount data ", data);
}
Also I able to get discount details using the URL https://myshop.myshopify.com/admin/discounts.json and the output as
{
discounts: [
{
id: 4128341132,
code: "GET4PRODUCT",
value: "10.00",
ends_at: null,
starts_at: "2017-03-09T00:00:00-08:00",
status: "enabled",
minimum_order_amount: "0.00",
usage_limit: null,
applies_to_id: 9720854796,
applies_once: true,
applies_once_per_customer: true,
discount_type: "fixed_amount",
applies_to_resource: "product",
times_used: 0,
applies_to: {
id: 9720854796,
title: "xxxxxxxxxxxxxx",
body_html: "<meta content="text/html; charset=utf-8" http-equiv="content-type">
<ul class="a-vertical a-spacing-none">
<li><span class="a-list-item">Outer Material: EVA Sheet</span></li>
<li><span class="a-list-item">Sole Material: Anti Slip EVA Sole</span></li>
</ul>",
vendor: "myshop",
product_type: "",
created_at: "2017-02-18T05:24:52-08:00",
handle: "adreno-mens-blue-slippers",
updated_at: "2017-02-18T05:28:20-08:00",
published_at: "2017-02-18T05:23:00-08:00",
template_suffix: null,
published_scope: "global",
tags: ""
}
}
]
}
But I unable to get discount objects using my application. Do I need to provide any other credentials or is there any other method to get the discount object from my application.
Please help me for getting discount json from an application.

HymnZ is correct, the Discounts endpoint is only API-accessible for Plus store accounts.
If you are not a Plus subscriber, you can access the Discounts endpoint in your browser with an admin-authenticated session, but not using API credentials.

Related

Load Sample Data in DynamoDB with AWS SDK for JavaScript

I'm using the guide from https://docs.amazonaws.cn/en_us/amazondynamodb/latest/developerguide/GettingStarted.NodeJs.02.html to learn how to load data from a json into a dynamoDB table. I have done step 2, however, when I run my code, only some movie files are successfully put into the table and some are not. For a movie that cannot be added, I receive this error:
Unable to add movie Meet Dave . Error JSON: {
"message": "Requested resource not found",
"code": "ResourceNotFoundException",
"time": "2020-11-30T17:38:59.402Z",
"requestId": "2D23NEFAB33E62C6PEFUFGGNM7VV4KQNSO5AEMVJF66Q9ASUAAJG",
"statusCode": 400,
"retryable": false,
"retryDelay": 28.791430704572328
}
Every time I delete the db and try re-run my code, different movies are successfully added and unsuccessfully added. My code is identical to the step 2 of the guide on the link above.
var allMovies = JSON.parse(fs.readFileSync("movie_data.json", "utf8"));
allMovies.forEach(function (movie) {
var movie_params = {
TableName: "Movies",
Item: {
year: movie.year,
title: movie.title,
info: movie.info,
},
};
docClient.put(movie_params, function (err, data) {
if (err) {
console.error(
"Unable to add movie",
movie.title,
". Error JSON:",
JSON.stringify(err, null, 2)
);
} else {
console.log("PutItem succeeded:", movie.title);
}
});
});
The movie data is a json file containing a list movies with attributes: title, year and info. Does anyone have any idea why this is not working correctly i.e. not putting all of the data successfully into the db table?.

DynamoDB InvalidParameterType Error While Trying To Put A New Item

I am trying to implement a DynamoDB based application to store some request data. I read the DynamoDB official documentation and currently I am following this official tutorial to do some basic operations.
I am using a local DynamoDB docker container. You can run it with this:
docker run -d -p 8000:8000 amazon/dynamodb-local:latest -jar DynamoDBLocal.jar -sharedDb
When I try to create a new table just same as the tutorial I gave above, I got no error, everything is fine:
var params = {
TableName: 'book',
KeySchema: [
{
AttributeName: 'title',
KeyType: 'HASH',
}
],
AttributeDefinitions: [
{
AttributeName: 'title',
AttributeType: 'S'
}
],
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1,
}
};
dynamodb.createTable(params, function(err, data) {
if (err) print(err); // an error occurred
else print(data); // successful response
});
But when I try to put some new items in it:
var params = {
TableName: 'book',
Item: { // a map of attribute name to AttributeValue
title: "Sample Application: CloudList",
chapter: 10
}
};
dynamodb.putItem(params, function(err, data) {
if (err) print(err); // an error occurred
else print(data); // successful response
});
I got this error:
31 validation error actually is equal to number of chars in title: Sample Application: CloudList. DynamoDB shell also did not recognized the print function which is given in the above tutorial. So I had to replace it with ppJson function. Where am I doing wrong and how can I put/delete/get items from DynamoDB via Web Shell? (and also via PHP code)
Edit: I also tried what Vikdor said in the comment, it seems I got rid of that UnexpectedParameter error but this time I got Invalid attribute value type error.
var params = {
TableName: 'book',
Item: { // a map of attribute name to AttributeValue
'title': {S: "Sample Application: CloudList"},
'chapter': {N: '10'}
}
};
This doc explains the structure of the Item key in the params passed to the API and your params should be as follows:
var params = {
TableName: "book",
Item: {
"title": {"S": "Sample Application: CloudList"},
"chapter": {"N": :10"}
}
};
Note that even the numbers should be enclosed in quotes.

Razor Pay checkout form not appearing and giving error as not a function

I am implementing razorPay payment in angular7 project.I am trying to open checkout form by creating a single instance of Razorpay and accessing its function open(). But instead it is throwing error "is not a function". I couldn't find any proper documentation regarding this.
However, If I try to simple create payment using razorpay, it opens up the window but there is no option for user to choose any method and hence it throws error again because directly creating payment will not add up any card(if method is 'card'). So it is necessary to open checkout form.
Here is my function I am using, firstly i create order on server to generate id and then proceed to payment.
buyPlan() {
let postdata = {
amount: 1000,
currency: "INR",
receipt: "1",
notes: {},
payment_capture: true
}
this.common.createOrder(postdata).subscribe(
(result: any) => {
console.log(result)
var razorpay = new this.winRef.nativeWindow.Razorpay({
key: 'dashboard_key_id',
image: 'assets/images/logo-1.png',
});
var data = {
amount: 1000,
currency: "INR",
email: 'abc#example.com',
contact: '9874563210',
notes: {
address: 'Sector 65 Delhi',
},
method: 'card',
order_id: result.data.id,
handler: function (response) {
alert(response.razorpay_payment_id);
}
};
razorpay.open();
}, (err: HttpErrorResponse) => {
}
);
}
For Custom Integration
Remove:
<script src="https://checkout.razorpay.com/v1/checkout.js"></script>
from index.html file
and put:
<script type="text/javascript" src="https://checkout.razorpay.com/v1/razorpay.js"></script>
inside <head></head> tag

correct way to use Stripe's stripe_account header from oauth with meteor

I'm trying to build a platform based on Meteor that uses Stripe Connect. I want to use the "preferred" authentication method from Stripe (Authentication via the Stripe-Account header, https://stripe.com/docs/connect/authentication) so that I can create plans and subscribe customers on behalf of my users. I cannot get it to work. I tried with a second params object, similar to the exemple in the documentation:
var stripeplancreate = Meteor.wrapAsync(Stripe.plans.create, Stripe.plans);
var plan = stripeplancreate({
amount: prod.price,
interval: prod.interv,
name: prod.name,
currency: prod.curr,
id: prod.id+"-"+prod.price+"-"+prod.curr+"-"+prod.interv,
metadata: { prodId: prod._id, orgId: org._id },
statement_descriptor: prod.descr
},{stripe_account: org.stripe_user_id});
but I get "Exception while invoking method 'createStripeProduct' Error: Stripe: Unknown arguments ([object Object]). Did you mean to pass an options object? See https://github.com/stripe/stripe-node/wiki/Passing-Options." which does not seem to accurately reflect the issue but prompted me to try adding stripe_account in the params object itself:
var stripeplancreate = Meteor.wrapAsync(Stripe.plans.create, Stripe.plans);
var plan = stripeplancreate({
amount: prod.price,
(...)
statement_descriptor: prod.descr,
stripe_account: org.stripe_user_id
});
I then get the following error: "Exception while invoking method 'createStripeProduct' Error: Received unknown parameter: stripe_account"
Any ideas? Has anybody managed to have Stripe Connect stripe_account authentication work with Meteor, especially with Meteor.wrapAsync(...)?
This should work for wrapAsync, HOWEVER check out my answer here for possible issues with wrapAsync - Wrapping Stripe create customer callbacks in Fibers in Meteor:
Here is also a great video on wrapAsync: https://www.eventedmind.com/feed/meteor-meteor-wrapasync
var createStripePlanAsync = function(shoppingCartObject, callback){
stripe.plans.create({
amount: shoppingCartObject.plan.totalPrice,
interval: shoppingCartObject.plan.interval,
name: shoppingCartObject.plan.planName,
currency: "usd",
id: shoppingCartObject.plan.sku //this ID needs to be unique!
}, function(err, plan) {
// asynchronously called
callback(err, plan);
});
};
var createStripePlanSync = Meteor.wrapAsync(createStripePlanAsync);
var myShoppingCart = {
customerInfo: {
name: "Igor Trout"
},
plan: {
totalPrice: 5000,
interval: "month",
name: "Set Sail For Fail Plan",
sku: "062015SSFF"
}
};
// Creates the plan in your Stripe Account
createStripePlanSync(myShoppingCart);
Later when you subscribe a customer to a plan you just refer to the plan via the id that you gave the plan when you first created it.
After much trying multiple things, for now, I just managed to get it working using the stripe-sync package instead of the "normal" one + wrapAsync.
try{
var plan = Stripe.plans.create({
amount: prod.price,
...
},{stripe_account: org.stripe_user_id});
}catch(error){
// ... process error
}

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

Categories

Resources