Created
January 21, 2015 12:46
-
-
Save lukasgraf/834d3f257f8be2ab1aaf to your computer and use it in GitHub Desktop.
External Payment Processor example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from ftw.shop.interfaces import IPaymentProcessor | |
from ftw.shop.interfaces import IShoppingCart | |
from ftwshop.adminpay.interfaces import IAdminpayAccountConfig | |
from ftwshop.adminpay.interfaces import IGlobalAdminpaySettings | |
from plone.registry.interfaces import IRegistry | |
from Products.Five.browser import BrowserView | |
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile | |
from zope.component import adapts | |
from zope.component import getMultiAdapter | |
from zope.component import getUtility | |
from zope.interface import implements, Interface | |
from ftwshop.adminpay.interfaces import IFtwShopAdminpayLayer | |
class AdminpayPaymentProcessor(object): | |
implements(IPaymentProcessor) | |
adapts(Interface, IFtwShopAdminpayLayer, Interface) | |
external = True | |
url = "http://www.adminpay.com" | |
launch_page = 'adminpay-launch' | |
title = "AdminPay" | |
image = """<img src="++resource++ftwshop-adminpay-resources/post-logo.png" />""" | |
description = """[Description of AdminPay service]""" | |
def __init__(self, context, request, foo): | |
self.context = context | |
self.request = request | |
def available(self): | |
registry = getUtility(IRegistry) | |
adminpay_settings = registry.forInterface(IGlobalAdminpaySettings) | |
if not adminpay_settings.multiple_adminpay_accounts: | |
return True | |
else: | |
# AdminPay is only available if: | |
# - All items in the cart are shipped by the same supplier | |
# - AND that supplier has an AdminPay account defined | |
cart = getMultiAdapter((self.context, self.request), IShoppingCart) | |
suppliers = cart.get_suppliers() | |
# All items from a single supplier? | |
if not cart.has_single_supplier(): | |
return False | |
# Supplier has an adminpay account configured? | |
if not suppliers[0].getField('shop_id').get(suppliers[0]): | |
return False | |
return True | |
class AdminpayLaunchView(BrowserView): | |
# URLs used for local development, integration testing against the | |
# test service, and production might look like this: | |
#external_processor_url = "http://localhost:8077/" | |
#external_processor_url = "http://payment.yellowworld.ch/Payment/invisible.aspx" | |
#external_processor_url = "https://payment-test.yellowworld.ch/Payment/invisible.aspx" | |
template = ViewPageTemplateFile('templates/adminpay-launch.pt') | |
def __call__(self): | |
account_config = getMultiAdapter((self.context, self.request), IAdminpayAccountConfig) | |
self.external_processor_url = account_config.payment_url | |
adminpay_xml = getMultiAdapter((self.context, self.request), | |
name='adminpay_xml') | |
# Set up acquisition chain for the view | |
adminpay_xml = adminpay_xml.__of__(self.context) | |
self.adminpay_data = adminpay_xml.encode_base64() | |
return self.template() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment