forked from agiliq/merchant
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
18 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,42 @@ | ||
''' | ||
Template tags for paypal offsite payments | ||
''' | ||
from paypal.standard.forms import PayPalPaymentsForm | ||
from paypal.standard.forms import PayPalPaymentsForm, PayPalEncryptedPaymentsForm | ||
from django import template | ||
from django.template.loader import render_to_string | ||
|
||
register = template.Library() | ||
|
||
class PayPalNode(template.Node): | ||
def __init__(self, integration): | ||
def __init__(self, integration, encrypted=False): | ||
self.integration = template.Variable(integration) | ||
self.encrypted = encrypted | ||
|
||
def render(self, context): | ||
int_obj = self.integration.resolve(context) | ||
if self.encrypted: | ||
form_class = PayPalEncryptedPaymentsForm | ||
else: | ||
form_class = PayPalPaymentsForm | ||
form_str = render_to_string("billing/paypal.html", | ||
{"form": PayPalPaymentsForm(initial=int_obj.fields), | ||
{"form": form_class(initial=int_obj.fields), | ||
"integration": int_obj}, context) | ||
return form_str | ||
|
||
|
||
@register.tag | ||
def paypal(parser, token): | ||
try: | ||
tag, int_obj = token.split_contents() | ||
except ValueError: | ||
raise template.TemplateSyntaxError("%r was expecting a single argument" %token.split_contents()[0]) | ||
return PayPalNode(int_obj) | ||
|
||
|
||
@register.tag | ||
def paypal_encrypted(parser, token): | ||
try: | ||
tag, int_obj = token.split_contents() | ||
except ValueError: | ||
raise template.TemplateSyntaxError("%r was expecting a single argument" %token.split_contents()[0]) | ||
return PayPalNode(int_obj, encrypted=True) |