示例#1
0
def charge(request):
    try:
        email = request.POST['Email']

        address = HpsAddress()
        address.address = request.POST['Address']
        address.city = request.POST['City']
        address.state = request.POST['State']
        address.zip = re.sub('[^0-9]', '', request.POST['Zip'])
        address.country = 'United States'

        card_holder = HpsCardHolder()
        card_holder.first_name = request.POST['FirstName']
        card_holder.last_name = request.POST['LastName']
        card_holder.address = address
        card_holder.phone = re.sub('[^0-9]', '', request.POST['PhoneNumber'])

        su_token = request.POST['token_value']
        response = charge_token(su_token, card_holder)
    except KeyError:
        traceback.print_exc()
        return HttpResponseRedirect(reverse('ssexample:index'))
    except (HpsCreditException, HpsGatewayException):
        traceback.print_exc()
        return HttpResponseRedirect(reverse('ssexample:index'))
    else:
        body = 'Success!\r\nThank you, %s, for your order of $15.15.' % card_holder.first_name
        print 'Transaction Id: %s' % response.transaction_id
        send_email(email, '*****@*****.**', 'Successful Charge!', body)
        return HttpResponseRedirect(reverse('ssexample:index'))
示例#2
0
def charge(request):
    try:
        email = request.POST['Email']

        address = HpsAddress()
        address.address = request.POST['Address']
        address.city = request.POST['City']
        address.state = request.POST['State']
        address.zip = re.sub('[^0-9]', '', request.POST['Zip'])
        address.country = 'United States'

        card_holder = HpsCardHolder()
        card_holder.first_name = request.POST['FirstName']
        card_holder.last_name = request.POST['LastName']
        card_holder.address = address
        card_holder.phone = re.sub('[^0-9]', '', request.POST['PhoneNumber'])

        su_token = request.POST['token_value']
        response = charge_token(su_token, card_holder)
    except KeyError:
        traceback.print_exc()
        return HttpResponseRedirect(reverse('ssexample:index'))
    except (HpsCreditException, HpsGatewayException):
        traceback.print_exc()
        return HttpResponseRedirect(reverse('ssexample:index'))
    else:
        body = 'Success!\r\nThank you, %s, for your order of $15.15.' % card_holder.first_name
        print 'Transaction Id: %s' % response.transaction_id
        send_email(email, '*****@*****.**', 'Successful Charge!', body)
        return HttpResponseRedirect(reverse('ssexample:index'))
    def POST(self):
        request = web.input()
        try:
            email = request['Email']

            address = HpsAddress()
            address.address = request['Address']
            address.city = request['City']
            address.state = request['State']
            address.zip = re.sub('[^0-9]', '', request['Zip'])
            address.country = 'United States'

            card_holder = HpsCardHolder()
            card_holder.first_name = request['FirstName']
            card_holder.last_name = request['LastName']
            card_holder.address = address
            card_holder.phone = re.sub('[^0-9]', '', request['PhoneNumber'])

            su_token = request['token_value']
            response = self.charge_token(su_token, card_holder)
        except KeyError:
            traceback.print_exc()
            raise web.seeother('/')
        except (HpsCreditException, HpsGatewayException):
            traceback.print_exc()
            raise web.seeother('/')
        else:
            body = '<h1>Success!</h1><p>Thank you, %s, for your order of $15.15.</p>' % card_holder.first_name
            print 'Transaction Id: %s' % response.transaction_id
            self.send_email(email, '*****@*****.**', 'Successful Charge!', body)
            raise web.seeother('/')
    def test_charge_ampersand_in_address(self):
        self.charge_service._config = TestServicesConfig.valid_services_config

        card_holder = HpsCardHolder()
        # card_holder.first_name = '&firstname' OK
        # card_holder.last_name = '&lastname' OK
        card_holder.address = HpsAddress()
        # card_holder.address.address = '&address' OK
        # card_holder.address.city = '&city' OK
        # card_holder.address.country = '&country' OK
        # card_holder.address.state = '&state' OK
        card_holder.address.zip = '40205'
        # card_holder.email = '&email'
        card_holder.phone = '2563235076'

        try:
            response = self.charge_service.charge(
                '5', 'usd', TestCreditCard.valid_visa, card_holder)
            self.assertIsNotNone(response)
            self.assertEqual('00', response.response_code)
        except HpsGatewayException, e:
            self.fail(e.message)
    def test_charge_ampersand_in_address(self):
        self.charge_service._config = TestServicesConfig.valid_services_config

        card_holder = HpsCardHolder()
        # card_holder.first_name = '&firstname' OK
        # card_holder.last_name = '&lastname' OK
        card_holder.address = HpsAddress()
        # card_holder.address.address = '&address' OK
        # card_holder.address.city = '&city' OK
        # card_holder.address.country = '&country' OK
        # card_holder.address.state = '&state' OK
        card_holder.address.zip = '40205'
        # card_holder.email = '&email'
        card_holder.phone = '2563235076'

        try:
            response = self.charge_service.charge('5', 'usd',
                                                  TestCreditCard.valid_visa,
                                                  card_holder)
            self.assertIsNotNone(response)
            self.assertEqual('00', response.response_code)
        except HpsGatewayException, e:
            self.fail(e.message)