Example #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'))
Example #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('/')