Skip to content

Commit

Permalink
extend transaction views with contact buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
agitator committed Sep 21, 2021
1 parent 76ba67f commit b51459f
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 52 deletions.
67 changes: 45 additions & 22 deletions src/bda/plone/wallee/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@
import transaction
import logging


logger = logging.getLogger(__name__)
_ = MessageFactory("bda.plone.wallee")

SKIP_RENDER_CART_PATTERNS.append('@@wallee_payment')
SKIP_RENDER_CART_PATTERNS.append('@@wallee_payment_success')
SKIP_RENDER_CART_PATTERNS.append("@@wallee_payment")
SKIP_RENDER_CART_PATTERNS.append("@@wallee_payment_success")
# SKIP_RENDER_CART_PATTERNS.append('@@wallee_payment_failed')


def get_wallee_settings():
return getUtility(IRegistry).forInterface(interfaces.IWalleeSettings)

class WalleeSettings:

class WalleeSettings:
@property
def space_id(self):
return get_wallee_settings().space_id
Expand All @@ -68,23 +68,42 @@ def api_secret(self):
return get_wallee_settings().api_secret



class WalleePaymentLightbox(Payment):
pid = "wallee_payment_lightbox"
label = _("wallee_payment", "Wallee Payment Lightbox")
clear_session = False


def init_url(self, uid):
return addTokenToUrl('%s/@@wallee_payment?uid=%s' % (self.context.absolute_url(), uid))

return addTokenToUrl(
"%s/@@wallee_payment?uid=%s" % (self.context.absolute_url(), uid)
)


class WalleePaymentLightboxView(BrowserView, WalleeSettings):

@property
def shop_admin_mail(self):
# This is a soft dependency indirection on bda.plone.shop
entry = "bda.plone.shop.interfaces.IShopSettings.admin_email"
shop_email = api.portal.get_registry_record(name=entry, default=None)
if shop_email is not None:
return shop_email
logger.warning("No shop master email was set.")
return "(no shopmaster email set)"

@property
def shop_admin_name(self):
# This is a soft dependency indirection on bda.plone.shop
entry = "bda.plone.shop.interfaces.IShopSettings.admin_name"
shop_name = api.portal.get_registry_record(name=entry, default=None)
if shop_name is not None:
return shop_name
logger.warning("No shop master name was set.")
return "(no shopmaster name set)"

def lightbox_script_url(self):
# breakpoint()

order = OrderData(self.context, uid=self.request.get("uid"))
order_data = order.order.attrs

Expand Down Expand Up @@ -117,7 +136,6 @@ def lightbox_script_url(self):
else:
shipping_address = billing_address


# create line items
line_items = []
# breakpoint()
Expand All @@ -138,11 +156,15 @@ def lightbox_script_url(self):
# quantity = float(booking.get("cart_item_count"))

# amountIncludingTax = booking_data.get("cart_item_price", ""))
amountIncludingTax = booking_data["net"] + (booking_data["net"] / 100 * booking_data["vat"])
amountIncludingTax = booking_data["net"] + (
booking_data["net"] / 100 * booking_data["vat"]
)

if booking_data.get("cart_item_discount", ""):
discounted_net = booking_data["net"] - booking_data["discount_net"]
amountIncludingTax = discounted_net + (discounted_net / 100 * booking_data["vat"])
amountIncludingTax = discounted_net + (
discounted_net / 100 * booking_data["vat"]
)

line_items.append(
LineItem(
Expand Down Expand Up @@ -233,17 +255,19 @@ def lightbox_script_url(self):
space_id=space_id, transaction=transaction
)


transaction_id = transaction_create.id


# create transaction model
transaction = TransactionCreate(
id=transaction_id,
merchant_reference=str(order.uid),
language=api.portal.get_current_language(),
success_url=addTokenToUrl(f"{base}/@@wallee_payment_success/?order_uid={str(order.uid)}&transaction_id={transaction_id}"),
failed_url=addTokenToUrl(f"{base}/@@wallee_payment_failed/?order_uid={str(order.uid)}&transaction_id={transaction_id}"),
success_url=addTokenToUrl(
f"{base}/@@wallee_payment_success/?order_uid={str(order.uid)}&transaction_id={transaction_id}"
),
failed_url=addTokenToUrl(
f"{base}/@@wallee_payment_failed/?order_uid={str(order.uid)}&transaction_id={transaction_id}"
),
line_items=line_items,
# auto_confirmation_enabled=True,
charge_retry_enabled=False,
Expand Down Expand Up @@ -281,12 +305,11 @@ def message(self):
if "transaction_id" in self.request:
transaction_id = self.request.get("transaction_id")

config = Configuration(
user_id=self.user_id,
api_secret=self.api_secret
)
config = Configuration(user_id=self.user_id, api_secret=self.api_secret)
transaction_service = TransactionServiceApi(configuration=config)
transaction = transaction_service.read(space_id=self.space_id, id=transaction_id)
transaction = transaction_service.read(
space_id=self.space_id, id=transaction_id
)

print(transaction)
return transaction
Expand All @@ -307,5 +330,5 @@ def status_update(self):
order = OrderData(self.context, order_uid)
order_tid = order.tid.pop()
if order_tid == transaction_id:
order.salaried = "yes"
order.salaried = "yes"
return order.salaried
34 changes: 14 additions & 20 deletions src/bda/plone/wallee/payment_lightbox.pt
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,39 @@
metal:use-macro="here/main_template/macros/master"
i18n:domain="bda.plone.wallee">

<head>
<metal:top fill-slot="top_slot">
<tal:border define="dummy python:request.set('disable_border', True)" />
</metal:top>
</head>

<body>

<metal:main fill-slot="main">
<tal:main-macro metal:define-macro="main">

<header>
<h1 class="documentFirstHeading"
i18n:translate="wallee_payment_title">wallee Payment</h1>
i18n:translate="wallee_payment_title">Payment</h1>
</header>

<div class="spinner-box w-auto d-flex justify-content-center align-items-center">
<div class="spinner-border text-secondary" style="width: 5rem; height: 5rem; min-height: 10rem;" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>

<div class="alert alert-secondary">
<span i18n:translate="payment_info_contact_us">Please contact us if you have questions or experience any problems.</span>
<a href=""
class="btn btn-primary"
tal:attributes="mailto: ${view/shop_admin_mail}?subject=E-Mail to ${view/shop_admin_name}"
i18n:translate="payment_button_contact_us">Contact us</a>
</div>

<script src='${view/lightbox_script_url}' type='text/javascript'></script>
<script type="text/javascript">

$(document).ready(function () {
window.LightboxCheckoutHandler.startPayment(undefined, function(){
alert('An error occurred during the initialization of the payment lightbox.');
});
});
</script>



<!-- <p tal:content="structure view/message">
Success Message
</p> -->


<!-- <p i18n:translate="wallee_payment_success_text">
Your Order has been completed successful.
</p> -->


</tal:main-macro>
</metal:main>

Expand Down
19 changes: 9 additions & 10 deletions src/bda/plone/wallee/success.pt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
metal:use-macro="here/main_template/macros/master"
i18n:domain="bda.plone.wallee">

<head>
<metal:top fill-slot="top_slot">
<tal:border define="dummy python:request.set('disable_border', True)" />
</metal:top>
</head>

<body>

<metal:main fill-slot="main">
Expand All @@ -22,18 +16,23 @@
i18n:translate="wallee_payment_success">Payment Success</h1>
</header>

<p>
Zahlung erfolgt: <span tal:content="view/status_update"></span>
</p>
<div tal:attributes="data-order-salaried view/status_update">
</div>

<p tal:content="structure view/message">
Success Message
</p>


<p i18n:translate="wallee_payment_success_text">
Your Order has been completed successful.
</p>

<a href=""
class="btn btn-primary"
tal:attributes="href context/absolute_url"
i18n:translate="payment_done_continue">continue</a>



</tal:main-macro>
</metal:main>
Expand Down

0 comments on commit b51459f

Please sign in to comment.