Skip to content

Instantly share code, notes, and snippets.

View jphungcode's full-sized avatar
🎯
Focusing

John Phung jphungcode

🎯
Focusing
View GitHub Profile
@jphungcode
jphungcode / generatepolyhedra.ipynb
Created June 8, 2019 13:46
generatePolyhedra.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jphungcode
jphungcode / scrollmagic_init.js
Created September 29, 2020 07:12
Scrollmagic Initalise
const intro = document.querySelector(".intro");
const controller = new ScrollMagic.Controller();
// set desired animation time long enough so that it doesn't skip frames when scrolling fast.
const animationTime = 2427;
// initialise scrollmagic scene
let scene = new ScrollMagic.Scene({
duration: animationTime,
@jphungcode
jphungcode / order_template.js
Last active October 21, 2020 02:44
1_wooCommercePFCIntegration
{
"Type":2, // 1 fulfilment, 2 for ordinary order
"CustomerId":"107085", // your account ID - this is mandatory
"ChannelId":158, // This is mandatory and refers to the base channel ID for shipping providers for a certain country. You can find the channelId from http://www.pfcexpress.com/webservice/APIWebService.asmx/getChannel. You will need to filter based on country code to determine what channelId to use.
"INorOut":0, // 0 for exports - most common
"IDCardNo":"",
"Remark":"",
"Products":[
{
"Price":64,
@jphungcode
jphungcode / woocommerce_request.js
Last active October 21, 2020 02:53
Woocommerce integration with PFC express
const crypto = require("crypto");
const fetch = require("isomorphic-fetch");
exports.wooComPushToPFC = functions.https.onRequest((req, res) => {
const method = req.method;
const headers = req.headers;
const data = req.body;
if (method !== "POST") {
res.status(501).send("Incorrect req method");
}
@jphungcode
jphungcode / woocommerce_webhook_payload.json
Created October 21, 2020 02:54
Woocommerce webhook payload data
"id": 52,
"parent_id": 0,
"status": "pending",
"order_key": "order_5836d85314887",
"number": 52,
"currency": "EUR",
"version": "2.6.8",
"prices_include_tax": false,
"date_created": "2016–11–24T12:08:00",
"date_modified": "2016–11–24T12:08:51",
@jphungcode
jphungcode / post_pfc_express_1.js
Created October 21, 2020 02:55
Start of function to post to pfc express endpoint
const pushOrder = (data) => {
return new Promise((resolve, reject) => {
if (data.status !== "processing") {
console.log("order not completed"); // we only want to push data when the order transitions to processing (paid)
reject("Order not completed");
}
// construct object for PFC
// POST data to PFC endpoint
}
}
const pfcEndpoint = "http://www.pfcexpress.com/webservice/v2/CreateShipment.aspx";
let lineItems = [];
// creating an update line items array for the necessary object attributes for PFC
for (let i = 0; i <= data.line_items.length - 1; i++) {
let item = data.line_items[i];
let temp_item = {
SKU: item.sku,
EnName: item.name,
CnName: "",
MaterialQuantity: item.quantity,
const pfcData = JSON.stringify({
Type: 2, // 1 fulfillment, 2 - ordinary
CustomerId: "107085", // 0 account ID for pfc
ChannelId: channelId,
Sender: "huangjia",
SendPhone: "0755–83727415",
SendAddress:
"4th Floor, Building C, №2, Road 1,Shangxue Science and Technology Park,Bantian street, Longgang District, Shenzhen, Guangdong Province, China",
SendCompany: "www.parcelfromchina.com",
SendEmail: "sales@pfcexpress.com",
const fetchConfig = {
method: "POST",
headers: {
Authorization: "Bearer " + functions.config().pfc.apikey, //api key is stored as a env variable
"Content-Type": "application/json",
},
body: pfcData,
};
fetch(pfcEndpoint, fetchConfig)
.then((response) => response.json())
exports.wooComPushToPFC = functions.https.onRequest((req, res) => {
const method = req.method;
const headers = req.headers;
const data = req.body;
if (method !== "POST") {
res.status(501).send("Incorrect req method");
}
const secret = functions.config().woocommerce.secret; //secret phrase set in woocommerce