本文整理汇总了Python中paypal.pro.helpers.PayPalWPP.doDirectPayment方法的典型用法代码示例。如果您正苦于以下问题:Python PayPalWPP.doDirectPayment方法的具体用法?Python PayPalWPP.doDirectPayment怎么用?Python PayPalWPP.doDirectPayment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类paypal.pro.helpers.PayPalWPP
的用法示例。
在下文中一共展示了PayPalWPP.doDirectPayment方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: purchase
# 需要导入模块: from paypal.pro.helpers import PayPalWPP [as 别名]
# 或者: from paypal.pro.helpers.PayPalWPP import doDirectPayment [as 别名]
def purchase(self, money, credit_card, options=None):
"""Using PAYPAL DoDirectPayment, charge the given
credit card for specified money"""
if not options:
options = {}
if not self.validate_card(credit_card):
raise InvalidCard("Invalid Card")
params = {}
params['creditcardtype'] = credit_card.card_type.card_name
params['acct'] = credit_card.number
params['expdate'] = '%02d%04d' % (credit_card.month, credit_card.year)
params['cvv2'] = credit_card.verification_value
params['ipaddress'] = options['request'].META.get("REMOTE_ADDR", "")
params['amt'] = money
if options.get("email"):
params['email'] = options["email"]
address = options.get("billing_address", {})
first_name = None
last_name = None
try:
first_name, last_name = address.get("name", "").split(" ")
except ValueError:
pass
params['firstname'] = first_name or credit_card.first_name
params['lastname'] = last_name or credit_card.last_name
params['street'] = address.get("address1", '')
params['street2'] = address.get("address2", "")
params['city'] = address.get("city", '')
params['state'] = address.get("state", '')
params['countrycode'] = address.get("country", '')
params['zip'] = address.get("zip", '')
params['phone'] = address.get("phone", "")
shipping_address = options.get("shipping_address", None)
if shipping_address:
params['shiptoname'] = shipping_address["name"]
params['shiptostreet'] = shipping_address["address1"]
params['shiptostreet2'] = shipping_address.get("address2", "")
params['shiptocity'] = shipping_address["city"]
params['shiptostate'] = shipping_address["state"]
params['shiptocountry'] = shipping_address["country"]
params['shiptozip'] = shipping_address["zip"]
params['shiptophonenum'] = shipping_address.get("phone", "")
wpp = PayPalWPP(options['request'])
try:
response = wpp.doDirectPayment(params)
transaction_was_successful.send(sender=self,
type="purchase",
response=response)
except PayPalFailure, e:
transaction_was_unsuccessful.send(sender=self,
type="purchase",
response=e)
# Slight skewness because of the way django-paypal
# is implemented.
return {"status": "FAILURE", "response": e}
示例2: process
# 需要导入模块: from paypal.pro.helpers import PayPalWPP [as 别名]
# 或者: from paypal.pro.helpers.PayPalWPP import doDirectPayment [as 别名]
def process(self, request, item):
"""Process a PayPal direct payment."""
from paypal.pro.helpers import PayPalWPP
wpp = PayPalWPP(request)
params = self.cleaned_data
params['creditcardtype'] = self.fields['acct'].card_type
params['expdate'] = self.cleaned_data['expdate'].strftime("%m%Y")
params['ipaddress'] = request.META.get("REMOTE_ADDR", "")
params.update(item)
try:
# Create single payment:
if 'billingperiod' not in params:
nvp_obj = wpp.doDirectPayment(params)
# Create recurring payment:
else:
if 'profileid' in params:
# Updating a payment profile.
nvp_obj = wpp.updateRecurringPaymentsProfile(params, direct=True)
else:
# Creating a payment profile.
nvp_obj = wpp.createRecurringPaymentsProfile(params, direct=True)
except PayPalFailure:
return False
return True
示例3: save
# 需要导入模块: from paypal.pro.helpers import PayPalWPP [as 别名]
# 或者: from paypal.pro.helpers.PayPalWPP import doDirectPayment [as 别名]
def save(request):
"""
Direct Paypal payment with credit card
"""
try:
cart = get_cart_data_from_request(request)
if 'order' not in request.GET:
raise Exception('no order data')
order_json = request.GET['order']
order_json = urllib.unquote(order_json)
order = json.loads(order_json)
wpp = PayPalWPP()
paypal_params = {
'ipaddress': request.META.get('REMOTE_ADDR'),
'creditcardtype': order['creditcardtype'],
'acct': order['acct'],
'expdate': order['cardmonth'] + order['cardyear'],
'cvv2': order['cvv2'],
'email': order['email'],
'firstname': order['card_first_name'],
'lastname': order['card_last_name'],
'street': order['b_street'],
'city': order['b_city'],
'state': order['b_state'],
'countrycode': order['b_countrycode'],
'zip': order['b_zip'],
'amt': cart['paymentrequest_0_amt'],
}
nvp = wpp.doDirectPayment(paypal_params)
order_data = nvp.response_dict.copy()
order_data.update(cart)
order_data.update(order)
order = create_order_from_direct_paypal(order_data)
data = {
'order_id': order.id,
}
send_order_email(order.email, order, order.items.all)
return HttpResponse(json.dumps(data), content_type='application/json')
except Exception, e:
print e
data = {
'error': e.message
}
return HttpResponseServerError(json.dumps(data), content_type='application/json')
示例4: process
# 需要导入模块: from paypal.pro.helpers import PayPalWPP [as 别名]
# 或者: from paypal.pro.helpers.PayPalWPP import doDirectPayment [as 别名]
def process(self, request, item):
"""Do a direct payment."""
from paypal.pro.helpers import PayPalWPP
wpp = PayPalWPP(request)
# Change the model information into a dict that PayPal can understand.
params = model_to_dict(self, exclude=self.ADMIN_FIELDS)
params['acct'] = self.acct
params['creditcardtype'] = self.creditcardtype
params['expdate'] = self.expdate
params['cvv2'] = self.cvv2
params.update(item)
# Create recurring payment:
if 'billingperiod' in params:
return wpp.createRecurringPaymentsProfile(params, direct=True)
# Create single payment:
else:
return wpp.doDirectPayment(params)
示例5: process
# 需要导入模块: from paypal.pro.helpers import PayPalWPP [as 别名]
# 或者: from paypal.pro.helpers.PayPalWPP import doDirectPayment [as 别名]
def process(self, request, item):
"""Do a direct payment."""
from paypal.pro.helpers import PayPalWPP
wpp = PayPalWPP(request)
# Change the model information into a dict that PayPal can understand.
params = model_to_dict(self, exclude=self.ADMIN_FIELDS)
params["ACCT"] = self.acct
params["CREDITCARDTYPE"] = self.creditcardtype
params["EXPDATE"] = self.expdate
params["CVV2"] = self.cvv2
params.update(item)
# Create recurring payment:
if "BILLINGPERIOD" in params:
return wpp.createRecurringPaymentsProfile(params, direct=True)
# Create single payment:
else:
return wpp.doDirectPayment(params)
示例6: process
# 需要导入模块: from paypal.pro.helpers import PayPalWPP [as 别名]
# 或者: from paypal.pro.helpers.PayPalWPP import doDirectPayment [as 别名]
def process(self, ipaddress, user, item):
"""Process a PayPal direct payment."""
from paypal.pro.helpers import PayPalWPP
wpp = PayPalWPP(ipaddress, user)
params = self.cleaned_data
params['creditcardtype'] = self.fields['acct'].card_type
params['expdate'] = self.cleaned_data['expdate'].strftime("%m%Y")
params['ipaddress'] = ipaddress
params.update(item)
try:
# Create single payment:
if 'billingperiod' not in params:
nvp_obj = wpp.doDirectPayment(params)
# Create recurring payment:
else:
nvp_obj = wpp.createRecurringPaymentsProfile(params, direct=True)
except PayPalFailure:
return None
return nvp_obj
示例7: process
# 需要导入模块: from paypal.pro.helpers import PayPalWPP [as 别名]
# 或者: from paypal.pro.helpers.PayPalWPP import doDirectPayment [as 别名]
def process(self, request, item):
"""
Do a direct payment.
"""
from paypal.pro.helpers import PayPalWPP
wpp = PayPalWPP(request)
params = self.cleaned_data
params["creditcardtype"] = self.fields["acct"].card_type
params["expdate"] = self.cleaned_data["expdate"].strftime("%m%Y")
params["ipaddress"] = request.META.get("REMOTE_ADDR", "")
params.update(item)
# Create single payment:
if "billingperiod" not in params:
response = wpp.doDirectPayment(params)
# Create recurring payment:
else:
response = wpp.createRecurringPaymentsProfile(params, direct=True)
return response