Slovo-Plugin-Prodan
view release on metacpan or search on metacpan
{
Prodan => {
migrate => 1,
consents => {
gdpr_url => '/ѿноÑно/ÑÑловиÑ.bg.html',
phone_url => $ENV{SLOVO_PRODAN_PHONE_URL},
delivery_prices_url => '/ѿноÑно/Ñени-доÑÑавки.bg.html',
},
econt => {
shop_id => $ENV{SLOVO_PRODAN_SHOP_ID},
private_key => $ENV{SLOVO_PRODAN_PRIVATE_KEY},
shippment_calc_url => 'https://delivery.econt.com/customer_info.php',
crupdate_order_endpoint =>
'https://delivery.econt.com/services/OrdersService.updateOrder.json',
create_awb_endpoint =>
'https://delivery.econt.com/services/OrdersService.createAWB.json'
}}
},
#...
],
lib/Slovo/Controller/Poruchki.pm view on Meta::CPAN
sub _create_order ($c, $o) {
state $shop = $c->config->{shop};
state $app = $c->app;
my $orders = $c->poruchki;
# POST to Econt to create order
my $_order_struct = $c->_order_struct($o);
my $eco_res = $app->ua->request_timeout(5)->post(
$shop->{crupdate_order_endpoint} =>
{'Content-Type' => 'application/json', Authorization => $shop->{private_key}},
json => $_order_struct
)->res;
$c->debug(
'req_url: ' => $shop->{crupdate_order_endpoint},
' $_order_struct:' => $_order_struct
);
$c->debug('$eco_res->json:' => $eco_res->json);
if ($eco_res->is_success) {
$o->{deliverer_id} = $eco_res->json->{id} + 0;
$o->{created_at} = $o->{tstamp} = time;
lib/Slovo/Controller/Poruchki.pm view on Meta::CPAN
state $shop = $c->config->{shop};
state $app = $c->app;
my $orders = $c->poruchki;
# $c->debug('Poruchka:' => $o);
# POST to Econt to create order
my $_order_struct = $c->_order_struct($o);
my $eco_res = $c->app->ua->request_timeout(5)->post(
$shop->{create_awb_endpoint} =>
{'Content-Type' => 'application/json', Authorization => $shop->{private_key}},
json => $_order_struct
)->res;
$c->debug(
'req_url: ' => $shop->{create_awb_endpoint},
' $_order_struct:' => $_order_struct
);
my $way_bill = $eco_res->json;
$c->debug('ÑоваÑиÑелниÑа $eco_res->json:' => $way_bill);
if ($eco_res->is_success) {
$o->{tstamp} = time;
lib/Slovo/Controller/Poruchki.pm view on Meta::CPAN
# GET /api/shop
# provides shipment data to the page on which the form for shipping the
# collected goods in the cart is called.
sub shop ($c) {
# TODO: some logic to use the right shop. We may have multiple
# shops(physical stores) from which we send the orders. For example we may
# choose the shop depending on the IP-location of the user. We want to use
# the closest store to the user to minimise delivery expenses.
# Copy data without private_key.
state $shop = {map { $_ eq 'private_key' ? () : ($_ => $c->config->{shop}{$_}) }
keys %{$c->config->{shop}}};
return $c->render(openapi => $shop);
}
# GET /api/gdpr_consent
# Provides various settings to the client side like the url for the page where
# are described the detailed conditions to use the site and the cookies policy
# - GDPR.
sub consents ($c) {
state $consents = $c->config('consents');
lib/Slovo/Plugin/Prodan.pm view on Meta::CPAN
# The keys in the $conf hash reference are named after the examples given at
# http://delivery.econt.com/services/
sub _configure_econt ($self, $conf) {
my $eco = $conf->{econt};
# ID на магазина в "ÐоÑÑави Ñ ÐконÑ"
$eco->{shop_id} //= 'demo';
# Ðод за ÑвÑÑзване
$eco->{private_key} //= 'demo';
# валÑÑа на магазина (валÑÑа на Ð½Ð°Ð»Ð¾Ð¶ÐµÐ½Ð¸Ñ Ð¿Ð»Ð°Ñеж)
$eco->{shop_currency} //= 'BGN';
# URL визÑализиÑÐ°Ñ ÑоÑма за доÑÑавка
$eco->{shippment_calc_url} //= 'https://delivery-demo.econt.com/customer_info.php';
# ÐндпойнÑа на ÑÑлÑгаÑа за ÑÑздаване или ÑедакÑиÑане на поÑÑÑка
$eco->{crupdate_order_endpoint}
//= 'https://delivery-demo.econt.com/services/OrdersService.updateOrder.json';
lib/Slovo/Plugin/Prodan.pm view on Meta::CPAN
{
Prodan => {
migrate => 1,
consents => {
gdpr_url => '/ѿноÑно/ÑÑловиÑ.bg.html',
phone_url => $ENV{SLOVO_PRODAN_PHONE_URL},
delivery_prices_url => '/ѿноÑно/Ñени-доÑÑавки.bg.html',
},
econt => {
shop_id => $ENV{SLOVO_PRODAN_SHOP_ID},
private_key => $ENV{SLOVO_PRODAN_PRIVATE_KEY},
shippment_calc_url => 'https://delivery.econt.com/customer_info.php',
crupdate_order_endpoint =>
'https://delivery.econt.com/services/OrdersService.updateOrder.json',
create_awb_endpoint =>
'https://delivery.econt.com/services/OrdersService.createAWB.json'
}}
},
#...
],
t/003_cart.t view on Meta::CPAN
my $t = Test::Mojo->with_roles('+Slovo')->install(
# from => to
undef() => $install_root,
# 0777
)->new('Slovo');
my $app = $t->app;
my $shop = $app->config->{shop};
is $shop->{shop_id} => $ENV{SLOVO_PRODAN_SHOP_ID}, 'right shop id';
is $shop->{private_key} => $ENV{SLOVO_PRODAN_PRIVATE_KEY}, 'right private key';
is $app->config->{consents}{phone_url} => $ENV{SLOVO_PRODAN_PHONE_URL}, 'right phone';
# /api/shop endpoind is accessed by function get_set_shop_data() in cart.js
$t->get_ok('/api/shop')->status_is(200)->json_is('',
{map { $_ eq 'private_key' ? () : ($_ => $shop->{$_}) } keys %$shop} =>
'no private key for the browser');
# The user collects product items. Opens the Econt form which is shown in a
# iframe similarly to as described in Econt integration documentation and
# clicks on OK of the confirm dialog. The JavaScript form of the cart makes
# the following request. The order data structure comes from the econt iframe
# and is slightly modified by our cart.js
# POST /api/poruchki
# Body of the request from jQuery cart.js to /api/poruchki:
my $json_request_body = <<'JSON';
t/slovo.conf view on Meta::CPAN
{
Prodan => {
migrate => 1,
consents => {
gdpr_url => '/ѿноÑно/ÑÑловиÑ.bg.html',
phone_url => $ENV{SLOVO_PRODAN_PHONE_URL},
delivery_prices_url => undef,
},
econt => {
shop_id => $ENV{SLOVO_PRODAN_SHOP_ID},
private_key => $ENV{SLOVO_PRODAN_PRIVATE_KEY},
shippment_calc_url => 'https://delivery.econt.com/customer_info.php',
crupdate_order_endpoint =>
'https://delivery.econt.com/services/OrdersService.updateOrder.json',
create_awb_endpoint =>
'https://delivery.econt.com/services/OrdersService.createAWB.json'
}}
},
],
( run in 0.434 second using v1.01-cache-2.11-cpan-a5abf4f5562 )