Commit 4c37efb7 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_jio: Use gadget to render Payment State

Payment State gadget translate the State of Sale Invoice Transaction and the Payment Transaction into a message meaningful to the User. (Unpaied, Waiting for Payment, Pay Now...).

Payment State gadget, in case of Payment Required, can include the Link to Pay Now using Payzen API.
parent 3e12184b
......@@ -37,8 +37,19 @@
type: "DateTimeField"
};
}
if (1 || (result.data.rows[i].hasOwnProperty("id"))) {
value = result.data.rows[i].id;
result.data.rows[i].value.translated_simulation_state_title = {
css_class: "",
description: "Payment State",
hidden: 0,
"default": {jio_key: value},
key: "translated_simulation_state_title",
url: "gadget_slapos_invoice_state.html",
title: "Payment State",
type: "GadgetField"
};
result.data.rows[i].value.download = {
css_class: "",
description: "Download Invoice",
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>964.59121.50434.9079</string> </value>
<value> <string>964.60286.59381.65058</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1516299992.78</float>
<float>1516369858.23</float>
<string>UTC</string>
</tuple>
</state>
......
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Background</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="handlebars.js"></script>
<script src="gadget_slapos_invoice_state.js"></script>
<script id="payment-link-template" type="text/x-handlebars-template">
<ul class="grid-items">
<li><a class="ui-btn ui-first-child ui-btn-icon-center" data-i18n="Pay Now" href={{invoice_url}}> Pay Now</a></li>
</ul>
</script>
<script id="payment-state-template" type="text/x-handlebars-template">
<ul class="grid-items">
<li>{{invoice_state}}</li>
</ul>
</script>
</head>
<body>
<button data-i18n="loading" type="submit" class="responsive ui-btn ui-icon-spinner ui-icon-spin ui-btn-icon-center ui-disabled" style="border:none;">loading</button>
</body>
</html>
\ No newline at end of file
/*globals console, window, rJS, RSVP, loopEventListener, i18n, Handlebars $*/
/*jslint indent: 2, nomen: true, maxlen: 80*/
(function (window, rJS, RSVP, Handlebars) {
"use strict";
var gadget_klass = rJS(window),
payment_link_source = gadget_klass.__template_element
.getElementById("payment-link-template")
.innerHTML,
payment_link_template = Handlebars.compile(payment_link_source),
payment_state_source = gadget_klass.__template_element
.getElementById("payment-state-template")
.innerHTML,
payment_state_template = Handlebars.compile(payment_state_source);
gadget_klass
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("translateHtml", "translateHtml")
.declareMethod("getContent", function () {
return {};
})
.declareMethod("render", function (options) {
var gadget = this;
return new RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getElement(),
gadget.getSetting("hateoas_url")
]);
})
.push(function (result) {
var hateoas_url = result[1],
element = result[0];
return gadget.jio_getAttachment(options.value.jio_key,
hateoas_url + options.value.jio_key +
"/AccountingTransaction_getPaymentStateAsHateoas")
.push(function (state) {
console.log(state);
var link, payment_transaction = state.payment_transaction;
if (payment_transaction !== null) {
link = payment_link_template({
invoice_state: state.state,
invoice_url: hateoas_url + payment_transaction +
"/PaymentTransaction_redirectToManualPayzenPayment"
});
} else {
link = payment_state_template({
invoice_state: state.state
});
}
element.innerHTML = link;
return state;
});
});
});
}(window, rJS, RSVP, Handlebars));
\ No newline at end of file
import json
state = context.AccountingTransaction_getPaymentState()
payment_transaction = None
if state == "Pay now":
payment_transaction = context.SaleInvoiceTransaction_getPayzenPaymentRelatedValue().getRelativeUrl()
return json.dumps({"state": state,
"payment_transaction": payment_transaction})
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>AccountingTransaction_getPaymentStateAsHateoas</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -130,5 +130,7 @@ web_page_module/rjs_gadget_erp5_page_slap_upgrade_decision_view_js
web_page_module/rjs_gadget_erp5_page_slap_regularisation_request_view_js
web_page_module/rjs_gadget_slapos_invoice_printout_js
web_page_module/rjs_gadget_slapos_invoice_printout_html
web_page_module/rjs_gadget_slapos_invoice_state_js
web_page_module/rjs_gadget_slapos_invoice_state_html
web_site_module/hostingjs
web_site_module/hostingjs/**
\ No newline at end of file
......@@ -118,6 +118,8 @@ web_page_module/rjs_gadget_slapos_instance_status_html
web_page_module/rjs_gadget_slapos_instance_status_js
web_page_module/rjs_gadget_slapos_invoice_printout_html
web_page_module/rjs_gadget_slapos_invoice_printout_js
web_page_module/rjs_gadget_slapos_invoice_state_html
web_page_module/rjs_gadget_slapos_invoice_state_js
web_page_module/rjs_gadget_slapos_network_status_html
web_page_module/rjs_gadget_slapos_network_status_js
web_page_module/rjs_gadget_slapos_panel_html
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment