当前位置: 首页>>代码示例>>Python>>正文


Python helpers.PayPalWPP类代码示例

本文整理汇总了Python中paypal.pro.helpers.PayPalWPP的典型用法代码示例。如果您正苦于以下问题:Python PayPalWPP类的具体用法?Python PayPalWPP怎么用?Python PayPalWPP使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了PayPalWPP类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: recurring

    def recurring(self, money, creditcard, options = None):
        if not options:
            options = {}
        params = {}
        params['profilestartdate'] = options.get('startdate') or datetime.datetime.now().strftime("%Y-%m-%dT00:00:00Z")
        params['startdate'] = options.get('startdate') or datetime.datetime.now().strftime("%m%Y")
        params['billingperiod'] = options.get('billingperiod') or 'Month'
        params['billingfrequency'] = options.get('billingfrequency') or '1'
        params['amt'] = money
        params['desc'] = 'description of the billing'
        
        params['creditcardtype'] = creditcard.card_type.card_name
        params['acct'] = creditcard.number
        params['expdate'] = '%02d%04d' % (creditcard.month, creditcard.year)
        params['firstname'] = creditcard.first_name
        params['lastname'] = creditcard.last_name

        wpp = PayPalWPP(options.get('request', {}))
        try:
            response = wpp.createRecurringPaymentsProfile(params, direct=True)
            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}
开发者ID:IbnSaeed,项目名称:merchant,代码行数:30,代码来源:pay_pal_gateway.py

示例2: purchase

    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}
开发者ID:IbnSaeed,项目名称:merchant,代码行数:60,代码来源:pay_pal_gateway.py

示例3: process

    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
开发者ID:ckxy7z,项目名称:django-paypal,代码行数:25,代码来源:forms.py

示例4: test_doReferenceTransaction_invalid

 def test_doReferenceTransaction_invalid(self, mock_request_object):
     reference_id = 'B-1234'
     amount = Decimal('10.50')
     mock_request_object.return_value = 'ack=Failure&l_errorcode=42&l_longmessage0=Broken'
     wpp = PayPalWPP(REQUEST)
     with self.assertRaises(PayPalFailure):
         wpp.doReferenceTransaction({'referenceid': reference_id,
                                     'amt': amount})
开发者ID:Krukov,项目名称:django-paypal,代码行数:8,代码来源:test_pro.py

示例5: save

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')
开发者ID:maartenvantigkhem,项目名称:fomotv,代码行数:58,代码来源:views.py

示例6: test_doExpressCheckoutPayment_invalid

 def test_doExpressCheckoutPayment_invalid(self, mock_request_object):
     ec_token = 'EC-1234567890'
     payerid = 'LXYZABC1234'
     item = self.ec_item.copy()
     item.update({'token': ec_token, 'payerid': payerid})
     mock_request_object.return_value = 'ack=Failure&l_errorcode=42&l_longmessage0=Broken'
     wpp = PayPalWPP(REQUEST)
     with self.assertRaises(PayPalFailure):
         wpp.doExpressCheckoutPayment(item)
开发者ID:Krukov,项目名称:django-paypal,代码行数:9,代码来源:test_pro.py

示例7: redirect_to_express

 def redirect_to_express(self):
     """
     First step of ExpressCheckout. Redirect the request to PayPal using the
     data returned from setExpressCheckout.
     """
     wpp = PayPalWPP(self.request)
     try:
         nvp_obj = wpp.setExpressCheckout(self.item)
     except PayPalFailure:
         self.context['errors'] = self.errors['paypal']
         return self.render_payment_form()
     else:
         return HttpResponseRedirect(express_endpoint_for_token(nvp_obj.token))
开发者ID:adamziel,项目名称:django-paypal,代码行数:13,代码来源:views.py

示例8: test_createBillingAgreement

 def test_createBillingAgreement(self, mock_request_object):
     mock_request_object.return_value = 'ack=Success&billingagreementid=B-XXXXX&version=%s' % VERSION
     wpp = PayPalWPP(REQUEST)
     nvp = wpp.createBillingAgreement({'token': 'dummy token'})
     call_args = mock_request_object.call_args
     self.assertIn('VERSION=%s' % VERSION, call_args[0][1])
     self.assertIn('METHOD=CreateBillingAgreement', call_args[0][1])
     self.assertIn('TOKEN=dummy+token', call_args[0][1])
     self.assertEquals(nvp.method, 'CreateBillingAgreement')
     self.assertEquals(nvp.ack, 'Success')
     mock_request_object.return_value = 'ack=Failure&l_errorcode=42&l_longmessage0=Broken'
     with self.assertRaises(PayPalFailure):
         nvp = wpp.createBillingAgreement({'token': 'dummy token'})
开发者ID:peteryao,项目名称:landlord,代码行数:13,代码来源:tests.py

示例9: test_doReferenceTransaction_valid

 def test_doReferenceTransaction_valid(self, mock_request_object):
     reference_id = 'B-1234'
     amount = Decimal('10.50')
     mock_request_object.return_value = 'ack=Success&paymentstatus=Completed&amt=%s&version=%s&billingagreementid=%s' % \
         (amount, VERSION, reference_id)
     wpp = PayPalWPP(REQUEST)
     nvp = wpp.doReferenceTransaction({'referenceid': reference_id,
                                       'amt': amount})
     call_args = mock_request_object.call_args
     self.assertIn('VERSION=%s' % VERSION, call_args[0][1])
     self.assertIn('METHOD=DoReferenceTransaction', call_args[0][1])
     self.assertIn('REFERENCEID=%s' % reference_id, call_args[0][1])
     self.assertIn('AMT=%s' % amount, call_args[0][1])
     self.assertEqual(nvp.method, 'DoReferenceTransaction')
     self.assertEqual(nvp.ack, 'Success')
开发者ID:Krukov,项目名称:django-paypal,代码行数:15,代码来源:test_pro.py

示例10: redirect_to_express

 def redirect_to_express(self):
     """
     First step of ExpressCheckout. Redirect the request to PayPal using the 
     data returned from setExpressCheckout.
     """
     wpp = PayPalWPP(self.request)
     nvp_obj = wpp.setExpressCheckout(self.item)
     if not nvp_obj.flag:
         pp_params = dict(token=nvp_obj.token, AMT=self.item['amt'], 
                          RETURNURL=self.item['returnurl'], 
                          CANCELURL=self.item['cancelurl'])
         pp_url = self.get_endpoint() % urlencode(pp_params)
         return HttpResponseRedirect(pp_url)
     else:
         self.context['errors'] = self.errors['paypal']
         return self.render_payment_form()
开发者ID:AnushPrem,项目名称:NewsBlur,代码行数:16,代码来源:views.py

示例11: test_doExpressCheckoutPayment

 def test_doExpressCheckoutPayment(self, mock_request_object):
     ec_token = 'EC-1234567890'
     payerid = 'LXYZABC1234'
     item = self.ec_item.copy()
     item.update({'token': ec_token, 'payerid': payerid})
     mock_request_object.return_value = 'ack=Success&token=%s&version=%spaymentinfo_0_amt=%s' % \
         (ec_token, VERSION, self.ec_item['paymentrequest_0_amt'])
     wpp = PayPalWPP(REQUEST)
     wpp.doExpressCheckoutPayment(item)
     call_args = mock_request_object.call_args
     self.assertIn('VERSION=%s' % VERSION, call_args[0][1])
     self.assertIn('METHOD=DoExpressCheckoutPayment', call_args[0][1])
     self.assertIn('TOKEN=%s' % ec_token, call_args[0][1])
     self.assertIn('PAYMENTREQUEST_0_AMT=%s' % item['paymentrequest_0_amt'],
                   call_args[0][1])
     self.assertIn('PAYERID=%s' % payerid, call_args[0][1])
开发者ID:Krukov,项目名称:django-paypal,代码行数:16,代码来源:test_pro.py

示例12: process

    def process(self, ipaddress, user, item):
        """Process a PayPal ExpressCheckout payment."""
        from paypal.pro.helpers import PayPalWPP
        wpp = PayPalWPP(ipaddress, user)
        params = self.cleaned_data
        params.update(item)

        try:
            # Create single payment:
            if 'billingperiod' not in params:
                nvp_obj = wpp.doExpressCheckoutPayment(params)
            # Create recurring payment:
            else:
                nvp_obj = wpp.createRecurringPaymentsProfile(params)
        except PayPalFailure:
            return None
        return nvp_obj
开发者ID:Kronuz,项目名称:django-paypal,代码行数:17,代码来源:forms.py

示例13: redirect_to_express

 def redirect_to_express(self):
     """
     First express flow step.
     Redirect to PayPal with the data in tow.
     
     """
     wpp = PayPalWPP(self.request)
     nvp_obj = wpp.setExpressCheckout(self.item)
     if not nvp_obj.flag:
         pp_params = dict(token=nvp_obj.token, 
                          AMT=self.item['amt'], 
                          RETURNURL=self.item['returnurl'], 
                          CANCELURL=self.item['cancelurl'])
         pp_url = SANDBOX_EXPRESS_ENDPOINT % urllib.urlencode(pp_params)
         return HttpResponseRedirect(pp_url)
     else:
         self.context = {'errors':'There was a problem contacting PayPal. Please try again later.'}
         return self.render_payment_form()
开发者ID:ckelly,项目名称:django-paypal,代码行数:18,代码来源:views.py

示例14: process

    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)
开发者ID:DjangoAdminHackers,项目名称:django-paypal,代码行数:18,代码来源:models.py

示例15: redirect_to_express

 def redirect_to_express(self):
     """
     First step of ExpressCheckout. Redirect the request to PayPal using the 
     data returned from setExpressCheckout.
     """
     wpp = PayPalWPP(self.request)
     try:
         nvp_obj = wpp.setExpressCheckout(self.item)
     except PayPalFailure:
         self.context["errors"] = self.errors["paypal"]
         return self.render_payment_form()
     else:
         pp_params = dict(
             token=nvp_obj.token,
             AMT=self.item["amt"],
             RETURNURL=self.item["returnurl"],
             CANCELURL=self.item["cancelurl"],
         )
         pp_url = self.get_endpoint() % urlencode(pp_params)
         return HttpResponseRedirect(pp_url)
开发者ID:renefs87,项目名称:simple_shop_frontend,代码行数:20,代码来源:views.py


注:本文中的paypal.pro.helpers.PayPalWPP类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。