Skip to content

Instantly share code, notes, and snippets.

@jeznag jeznag/test.js
Created May 6, 2019

Embed
What would you like to do?
sun-energy-green-energy
const request = require("request-promise");
const clientID =
"REDACTED";
const clientSecret =
"REDACTED";
async function createSTC() {
const timestamp = new Date().toISOString();
const signatureString = `GD:${clientID}${timestamp}${clientSecret}`;
const crypto = require("crypto");
const md5Signature = crypto
.createHash("md5")
.update(signatureString)
.digest("hex");
const url = "http://greendeal.client.com.au/rapi/v1";
const headers = {
client_id: clientID,
signature: md5Signature,
timestamp
};
const dataToSend = {
trade_mode: "Cash",
claimed_quantity: 71,
po_reference: '123444',
price: "32.65",
gst: false,
status: "Approved",
payment_status: "Paid",
submit_date: "2018-09-10",
credit_memo: "\tF809116650575",
unqualified_reasons: "",
failed_reasons: "",
created_via: "GWT",
note: "",
received_date: "2018-09-10T00:00:00.000+10:00",
reference: "JSmith",
amount: "2318.15",
created_at: "2018-08-31T11:09:50.000+10:00",
finished_at: null,
finished_location: null,
install_detail: {
property_type: "Residential",
latitude: null,
longitude: null,
special_address: "",
installation_address: "10 Jomarant PLACE KAWANA , QLD , 4701",
single_or_multi_story: "Single story",
same_as_postal_address: true
},
owner_detail: {
first_name: "Jay",
last_name: "Smith",
state: "QLD",
phone: "0439776799",
delivery_type: "",
delivery_number: "",
suburb: "KAWANA",
post_code: "4701",
type: "Individual",
type_name: "Jay Smith",
address_type: "Physical",
address: "10 Jomarant PLACE KAWANA , QLD , 4701"
},
system_detail: {
deemed_years: 13,
installation_date: "2018-09-05",
type_of_connection:
"Connected to an electricity grid without battery storage",
system_mounting_type: "Building or structure",
rated_output: 3.99,
complete_unit: "YES",
additional_upgrade_system_details: "",
panel_brand: "Canadian Solar Inc",
panel_model: "CS6K-285P",
number_panels: 14,
number_inverters: "1",
watts_per_panel: 285,
inverter_manufacture: "Jiangsu GoodWe Power Supply Technology Co Ltd",
inverter_series: "DNS",
inverter_model: "GW3000D-NS"
},
serial_numbers: [
"11807030791259",
"11807030791345",
"11807030791348",
"11807030792732",
"11807030792735",
"11807030792807",
"11807030792852",
"11807030792884",
"11807030792894",
"11807030792899",
"11807030793041",
"11807030793155",
"11807030793219",
"11807030793224"
],
serial_numbers_photo: [
"https://s3-ap-southeast-2.amazonaws.com/solarbrains3-test/uploads/pvd_serial_number/photo/1435635/2e0e22e9-829e-42f6-a1ee-2f1c21e30fc8.png",
"https://s3-ap-southeast-2.amazonaws.com/solarbrains3-test/uploads/pvd_serial_number/photo/1435636/b836773c-062a-45fd-a3ce-a75b3aaae38d.png",
"https://s3-ap-southeast-2.amazonaws.com/solarbrains3-test/uploads/pvd_serial_number/photo/1435637/43223957-7cdf-47b3-9e0b-e38919e74b44.png",
"https://s3-ap-southeast-2.amazonaws.com/solarbrains3-test/uploads/pvd_serial_number/photo/1435638/0a3edc5a-494a-4d22-b25b-c20b25cc3aa7.png",
"https://s3-ap-southeast-2.amazonaws.com/solarbrains3-test/uploads/pvd_serial_number/photo/1435639/a0660809-eea2-4f84-9347-80d626d8b22b.png",
"https://s3-ap-southeast-2.amazonaws.com/solarbrains3-test/uploads/pvd_serial_number/photo/1435640/09ca81c9-a120-4b3d-a390-88e9ec46bc50.png",
"https://s3-ap-southeast-2.amazonaws.com/solarbrains3-test/uploads/pvd_serial_number/photo/1435641/a16062ea-ec38-4a5e-9f4c-a6fe7d3d46ee.png",
"https://s3-ap-southeast-2.amazonaws.com/solarbrains3-test/uploads/pvd_serial_number/photo/1435642/d164f5a5-22b7-4cb6-b4aa-46e542d47660.png",
"https://s3-ap-southeast-2.amazonaws.com/solarbrains3-test/uploads/pvd_serial_number/photo/1435643/591c6baa-fda4-4afa-a9b8-67110edd2a8a.png",
"https://s3-ap-southeast-2.amazonaws.com/solarbrains3-test/uploads/pvd_serial_number/photo/1435644/b91500c6-abab-4a65-8e3d-4e27826b035f.png",
"https://s3-ap-southeast-2.amazonaws.com/solarbrains3-test/uploads/pvd_serial_number/photo/1435645/f1e36ac9-1fae-4c39-b86c-53dd8cd9a8d5.png",
"https://s3-ap-southeast-2.amazonaws.com/solarbrains3-test/uploads/pvd_serial_number/photo/1435646/a2a9fd49-a130-47ad-91b9-5f4586027f02.png",
"https://s3-ap-southeast-2.amazonaws.com/solarbrains3-test/uploads/pvd_serial_number/photo/1435647/980e6218-0932-4927-ba4d-ac7bb384c050.png",
"https://s3-ap-southeast-2.amazonaws.com/solarbrains3-test/uploads/pvd_serial_number/photo/1435660/ab17683b-90b9-414b-8808-9e23c021fbd4.png"
],
stc_documents: [],
coc_documents: [],
invoice_documents: [],
other_documents: []
};
console.log(headers);
const panels = await request({
method: 'POST',
uri: `${url}/pvds.json`,
qs: headers,
json: dataToSend
});
console.log(panels);
}
createSTC();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.