Skip to content

Instantly share code, notes, and snippets.

View tiagomatos's full-sized avatar

Tiago Matos tiagomatos

View GitHub Profile
@tiagomatos
tiagomatos / gist:0e1a62e8542ed87ea913b3eef415ae7e
Created June 22, 2020 23:42
How to synchronize stocks between Jumpseller Store and my ERP system (using the API).
To design a proper architecture to sincronize product stocks between a Jumpseller store and a ERP (or any similar system), consider:
1. Define a storage system (a MySQL, SQLite or even a plain-text file works perfectly) to hold at least two columns: jumpseller_product_id and erp_id
2. Record each part of IDs, jumpseller_product_id and erp_id, using Jumpseller GET /products endpoint, like:
jumpseller_product_id, erp_id
123456, adidas-red-43
123457, adidas-red-44
123458, adidas-red-45
3. Once the matching of all products from Jumpseller Store and the ERP system is done,
4. You can start work on keeping stock updated, by adding a third column: synced_at, like:
@tiagomatos
tiagomatos / external_payment_gateway.php
Created June 12, 2020 16:47
External Payment Gateway Integration in PHP
public function dataJumpseller(Request $data)
{
$secretKey = "secreto_jumpseller";
$params = array( "x_account_id" => "223504", "x_amount" => "123.0", "x_currency" => "EUR", "x_reference" => "1001", , x_result: "completed", x_timestamp: '2014-03-24T12:15:41Z', "x_message" => "\\nProducto:\\n1 x Energise EDT 125 ML: 29.500 EUR\\nImpuesto: €6.785,00" );
$keys = array_keys($params);
sort($keys);
$toSign = "";
@tiagomatos
tiagomatos / google_maps_level3.json
Created May 21, 2020 19:24
Google Maps Level Mapping to Jumpseller Municipalities
Arica y Parinacota: {
'8261387': Arica: { "googleKey":"Arica", "v":"15101" },
'8261252': Camarones: { "googleKey":"Camarones", "v":"15102" },
'8261463': Putre: { "googleKey":"Putre", "v":"15201" },
'8261451': General Lagos: { "googleKey":"General Lagos", "v":"15202" },
}
Tarapacá:
'8261207': Iquique: { "googleKey":"Iquique", "v":"01101" },
'8261202': Alto Hospicio: { "googleKey":"Alto Hospicio", "v":"01107" },
'8261350': Pozo Almonte: { "googleKey":"Pozo Almonte", "v":"01401" },
@tiagomatos
tiagomatos / api_create_orders.curl
Created May 14, 2020 01:04
Create an Order, via Jumpseller API, with Product Variants
curl -X POST -d '{ "order": {"status": "Paid", "products": [{ "id": 4803531,"variant_id": 9072280, "qty": 1}], "customer": {"id": 1609949}}}' "http://api.jumpseller.com/v1/orders.json?login=XXX&authtoken=XXX" -H "Content-Type:application/json"
@tiagomatos
tiagomatos / facto_hooks.php
Last active March 23, 2020 21:16
facto_hooks.php
// editar webhook
$data = array("event" => "order_paid",
"url" => "https://conexiondes.facto.cl/conector_jumpseller.php?user=$user&password=$pass",
);
$data_hook = json_encode(array("hook" => $data));
$url = "https://api.jumpseller.com/v1/hooks/".$id.".json";
$ch = curl_init();
@tiagomatos
tiagomatos / sku_name_duplicated.rb
Created August 12, 2019 18:04
Duplicated Products (via SKU / name comparison)
store = Store.find_by(code: "XXX")
store.products.all.each do |product|
p "product id: #{product.id} SKU duplicated from #{store.products.where(sku: product.sku).map(&:id)}" if store.products.where(sku: product.sku).size >= 2
p "product id: #{product.id} name duplicated from #{store.products.where(name: product.name).map(&:id)}" if store.products.where(name: product.name).size >= 2
end
@tiagomatos
tiagomatos / heroku_ip_address.rb
Created February 22, 2019 21:09
Get Heroku Public IP
# at heroku console
heroku ps:exec -a jumpseller-apps -d worker.1 --ssh
# then
curl 'https://api.ipify.org'
@tiagomatos
tiagomatos / php_post_complete.php
Created January 23, 2019 17:24
Jumpseller POST Complete to External Payment G ateway
$response_params = array(
"x_account_id" => $this->params['chave_api'],
"x_amount" => $this->params['valor'],
"x_currency" => "EUR",
"x_reference" => $this->params['identificador'],
"x_result" => "completed",
"x_timestamp" => date('Y-m-d') . 'T' . date('H:i:s') . 'Z',
"x_message" => "Pagamento realizado com sucesso"
);
// $response_params['x_signature'] = $this->generateSignature($response_params);
function payment_cost_order_product_id(cart_json){
var id = null;
$.each(cart_json.products, function( i, order_product ){
if(order_product.product_id == '287177'){ // product for adding payment cost.
id = order_product.id;
}
});
return id; // return order_product.id if found
}
@tiagomatos
tiagomatos / correos_chile_PES.rb
Last active June 11, 2018 21:50
Jumpseller Correos de Chile PES
require 'net/http'
HOST = 'http://b2b.correos.cl/ServicioAdmisionCEPExterno/cch/ws/enviosCEP/externo/implementacion/ServicioExternoAdmisionCEP.asmx?WSDL'
def post_xml xml_string
uri = URI.parse HOST
request = Net::HTTP::Post.new uri.path
request.body = xml_string
request.content_type = 'text/xml'
response = Net::HTTP.new(uri.host, uri.port).start { |http| http.request request }