Sent the previous email prematurely. So, here is a working example:
Create your checkout form and if the form is valid populate the following dict with the form data: data = { 'VPSProtocol': settings.VPS_PROTOCOL, 'TxType': settings.TXTYPE, 'VendorTxCode': b32encode(uuid.uuid4().bytes).strip('=').lower(), # Generate a new transaction ID 'Vendor': settings.SAGEPAY_VENDOR, 'Amount': order.totalAmountAsString(), 'Currency': 'GBP', 'Description': 'BC Order ID: %s' % order.orderId, 'CardHolder': clean_checkout_form['card_name'], 'CardNumber': clean_checkout_form['card_number'], 'ExpiryDate': clean_checkout_form['card_expiry'].strftime('%m%y'), 'CV2': clean_checkout_form['card_CVV'], 'CardType': clean_checkout_form['card_type'], 'CustomerEMail': clean_checkout_form['email'].lower(), 'BillingSurname': clean_checkout_form['lastname'], # 20 Chars 'BillingFirstnames': clean_checkout_form['firstname'], # 20 Chars 'BillingAddress1': clean_checkout_form['billing_address'], # Truncate to 100 Chars 'BillingCity': clean_checkout_form['billing_city'], # Truncate to 40 Chars 'BillingPostCode': clean_checkout_form['billing_postcode'], # Truncate to 10 Chars 'BillingCountry': clean_checkout_form['billing_country'], # 2 letter country code 'DeliverySurname': clean_checkout_form['lastname'], # 20 Chars 'DeliveryFirstnames': clean_checkout_form['firstname'], # 20 Chars 'DeliveryAddress1': clean_checkout_form['shipping_address'], # 100 Chars 'DeliveryCity': clean_checkout_form['shipping_city'], # 40 Chars 'DeliveryPostCode': clean_checkout_form['shipping_postcode'], # 10 Chars 'DeliveryCountry': clean_checkout_form['shipping_country'], # 2 letter country code 'CreateToken': 1 } Your field names will be different. Encode it: request_body = encode_transaction_request(data) Then make a request: # Show customer success page or failure page (failure page has option to go back and try again) try: # Fire request to SagePay which creates the transaction response = requests.post(settings.SAGEPAY_URL, data=request_body, headers={"Content-Type":"application/x-www-form-urlencoded"}) # Does nothing on 200, but raises exceptions for other statuses response.raise_for_status() # RequestException covers network/DNS related problems as well as non-200 # responses except RequestException as e: raise SagePayError(repr(e)), None, sys.exc_info()[2] Then check the response: response_data = decode_transaction_response(response.text) # Anything other than a status of OK throws an exception (Note that SagePay # can return the status 'OK REPEATED' if the VendorTxCode refers to an in- # progress transaction, but because we generate unique IDs every time we # hit SagePay we should never get this -- if we do, it's an error) if response_data['Status'] != 'REGISTERED': exc = SagePayError(response_data['StatusDetail']) exc.status = response_data['Status'] context = Context({ 'checkout_form': bc_checkout_form, 'order': order, 'products': order.products.all(), 'failure_message': response.text }) context.update(csrf(request)) return render_to_response( 'whosounds/whosounds_checkout.html', context, context_instance=RequestContext(request) ) Note that I'm looking for "REGISTERED" here because I'm doing pre-auths, but your response may differ depending on "TXTYPE". Then: SagePayTransaction.objects.create( vendor_tx_id=data['VendorTxCode'], request=data, response=response_data, ) vendor_tx_code = data['VendorTxCode'] ### b32encode(uuid.uuid4().bytes).strip('=').lower() ### I hope that will get you started. Basically, that's all you need to process a transaction with sagepay. Note that this is no using 3D secure. Cheers, Mario Two Blokes with a Postie On 10 April 2013 09:54, Mario Gudelj <mario.gud...@gmail.com> wrote: > Hey sparky, > > I hope this helps: > > Create your checkout form and if the form is valid populate the following > dict with the form data: > > data = { > 'VPSProtocol': settings.VPS_PROTOCOL, > 'TxType': settings.TXTYPE, > 'VendorTxCode': > b32encode(uuid.uuid4().bytes).strip('=').lower(), # Generate a new > transaction ID > 'Vendor': settings.SAGEPAY_VENDOR, > 'Amount': order.totalAmountAsString(), > 'Currency': 'GBP', > 'Description': 'BC Order ID: %s' % order.orderId, > 'CardHolder': clean_checkout_form['card_name'], > 'CardNumber': clean_checkout_form['card_number'], > 'ExpiryDate': > clean_checkout_form['card_expiry'].strftime('%m%y'), > 'CV2': clean_checkout_form['card_CVV'], > 'CardType': clean_checkout_form['card_type'], > 'CustomerEMail': clean_checkout_form['email'].lower(), > 'BillingSurname': clean_checkout_form['lastname'], # 20 > Chars > 'BillingFirstnames': clean_checkout_form['firstname'], # > 20 Chars > 'BillingAddress1': clean_checkout_form['billing_address'], > # Truncate to 100 Chars > 'BillingCity': clean_checkout_form['billing_city'], # > Truncate to 40 Chars > 'BillingPostCode': > clean_checkout_form['billing_postcode'], # Truncate to 10 Chars > 'BillingCountry': clean_checkout_form['billing_country'], > # 2 letter country code > 'DeliverySurname': clean_checkout_form['lastname'], # 20 > Chars > 'DeliveryFirstnames': clean_checkout_form['firstname'], # > 20 Chars > 'DeliveryAddress1': > clean_checkout_form['shipping_address'], # 100 Chars > 'DeliveryCity': clean_checkout_form['shipping_city'], # 40 > Chars > 'DeliveryPostCode': > clean_checkout_form['shipping_postcode'], # 10 Chars > 'DeliveryCountry': > clean_checkout_form['shipping_country'], # 2 letter country code > 'CreateToken': 1 > } > > Your field names will be different. > > Encode it: > > > > On 10 April 2013 02:27, sparky <cfspa...@gmail.com> wrote: > >> I want to use >> django-sagepay<https://github.com/timetric/django-sagepay/tree/master/django_sagepay>. >> However, it doesn't seem to have any examples or test.py that I can learn >> from. being a newbie I need docs! >> >> Does anyone know of any examples of use? I'm very familiar with sagepay, >> just need to know how to implement this application into my app. >> >> For example, any app I can look at that makes use of this >> django-sagepay<https://github.com/timetric/django-sagepay/tree/master/django_sagepay> >> ? >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to django-users+unsubscr...@googlegroups.com. >> To post to this group, send email to django-users@googlegroups.com. >> Visit this group at http://groups.google.com/group/django-users?hl=en. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.