def _show_payment_form(self, context, payment): """This view load the paybox cgi. That script redirect on paybox serveur to show the payment form. It must be call via the method show_payment_form() of payment resource. """ payments = self.parent shop = payments.parent # We get the paybox CGI path on serveur cgi_path = Path(prefix).resolve2('bin/paybox.cgi') # Configuration kw = {} kw['PBX_CMD'] = payment['ref'] kw['PBX_TOTAL'] = int(payment['amount'] * 100) # Basic configuration kw['PBX_MODE'] = '4' kw['PBX_LANGUE'] = 'FRA' kw['PBX_TYPEPAIEMENT'] = 'CARTE' kw['PBX_WAIT'] = '0' kw['PBX_RUF1'] = 'POST' kw['PBX_RETOUR'] = "ref:R\;transaction:T\;autorisation:A\;amount:M\;advance_state:E\;payment:P\;carte:C\;sign:K" # PBX Retour uri base_uri = context.uri.resolve(context.get_link(self)) for option in PBXState.get_options(): key = option['pbx'] state = option['name'] uri = '%s/;end?state=%s' % (base_uri, state) kw[key] = '"%s"' % uri # PBX_REPONDRE_A (Url to call to set payment status) kw['PBX_REPONDRE_A'] = '"%s/;confirm_payment"' % base_uri # Configuration for key in ['PBX_SITE', 'PBX_IDENTIFIANT', 'PBX_RANG', 'PBX_DIFF', 'PBX_AUTOSEULE']: kw[key] = self.get_property(key) kw['PBX_DEVISE'] = shop.get_property('devise') # PBX_PORTEUR kw['PBX_PORTEUR'] = context.user.get_property('email') # En mode test: if not self.get_property('real_mode'): kw.update(self.test_configuration) # Attributes attributes = ['%s=%s' % (x[0], x[1]) for x in kw.items()] # Build cmd cmd = '%s %s' % (cgi_path, ' '.join(attributes)) # Call the CGI file = popen(cmd) # Check if all is ok result = file.read() html = match ('.*?<HEAD>(.*?)</HTML>', result, DOTALL) if html is None: raise ValueError, u"Error, payment module can't be load" # We return the payment widget html = html.group(1) # Encapsulate in pay view view = payments.pay_view(body=HTMLFile(string=html).events) return view.GET(self, context)
def get_namespace(self, resource, context): namespace = PaymentWay_EndView.get_namespace(self, resource, context) erreur = context.query['NUMERR'] if erreur: # Send mail root = context.root server = context.server from_addr = server.smtp_from subject = u'Paybox problem' body = 'Paybox error: %s' % PayboxCGIErrors.get_value(erreur) root.send_email(from_addr, subject, from_addr, body) state = PBXState.get_value(context.query['state']) namespace['state'] = state.gettext() return namespace