This package provides utilities for using CyberSource Secure Acceptance Hosted Checkout.
Project description
Django CyberSource Hosted Checkout
This package provides utilities for using CyberSource Secure Acceptance Hosted Checkout.
It assumes you have a working knowledge of the product and profiles; you can read the CyberSource manual here.
The heavy lifting it does is properly creating the signed_date_time
, fields_to_sign
, and signature
fields and automatically include them in the POST
, along with any fields you need to pass along.
Installation
First, pip install django-cybersource-hosted-checkout
, and add 'cybersource_hosted_checkout'
to your INSTALLED_APPS
list.
Settings
These settings are required to be present in Django's settings.
CYBERSOURCE_URL
- For testing / development:
https://testsecureacceptance.cybersource.com/pay
- For production:
https://secureacceptance.cybersource.com/pay
- For testing / development:
CYBERSOURCE_PROFILE_ID
= '[Your CyberSource Profile ID]'CYBERSOURCE_ACCESS_KEY
= '[Your CyberSource Access Key]'CYBERSOURCE_SECRET_KEY
= '[Your CyberSource Secret Key]'
Code and Configuration
models.py
Create a model in an app in your Django project which inherited from AstractCyberSourceTransaction
; you can add any additional fields you wish to store. Then makemigrations
and migrate
.
from cybersource_hosted_checkout.models import AstractCyberSourceTransaction
class CyberSourceTransaction(AstractCyberSourceTransaction):
"""
Stores credit card transaction receipts made with CyberSource.
"""
user = models.ForeignKey(User, on_delete=models.CASCADE)
views.py
You can call the relevant functions from within a FormView.
from uuid import uuid4
from my_app.models import CyberSourceTransaction
class AddCourseView(LoginRequiredMixin, SuccessMessageMixin, FormView):
template_name = 'my_app/transaction.html'
form_class = TransactionForm
success_url = reverse_lazy('home')
success_message = "Your transaction has been completed."
def form_valid(self, form, request, **kwargs):
# Create a transaction in the database before we pass to CyberSource;
# we will update this with the course on the return call from CyberSource
transaction_uuid = uuid4().hex
transaction = CyberSourceTransaction()
transaction.transaction_uuid = transaction_uuid
transaction.user = request.user
transaction.save()
# Fields to pass to CyberSource
context = super().get_context_data(**kwargs)
fields = {}
fields['profile_id'] = settings.CYBERSOURCE_PROFILE_ID
fields['access_key'] = settings.CYBERSOURCE_ACCESS_KEY
fields['amount'] = '99.99'
fields['transaction_uuid'] = transaction_uuid
fields['bill_to_forename'] = request.user.first_name
fields['bill_to_surname'] = request.user.last_name
fields['bill_to_email'] = request.user.email
fields['locale'] = 'en-us'
fields['currency'] = 'usd'
fields['transaction_type'] = 'sale'
fields['reference_number'] = transaction.id
context = sign_fields_to_context(fields, context)
# Render a page which POSTs to CyberSource via JavaScript.
return render(
request,
'cybersource_hosted_checkout/post_to_cybersource.html',
context=context,
)
Release Notes
0.1.0
- Initial release
Contributors
- Timothy Allen (https://github.com/FlipperPA)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-cybersource-hosted-checkout-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4947edb4f59f29c04dbab86e5f862d7f500146eaf5c1b9871b56e59216a8621 |
|
MD5 | 2d954d7d8b9ebe2092f495a3a42c1682 |
|
BLAKE2b-256 | ca979fe8b3107734919b958f863fe0e27a4792c0bd4a349686321bceca921017 |
Hashes for django_cybersource_hosted_checkout-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f7b121317edc5bae93ed398d107d511c1eb1111664f14c1c146cd5bacf13665 |
|
MD5 | 45af06bc3e32ede602e32c8e3e6a9909 |
|
BLAKE2b-256 | 2e6170f4b5f5a3a598389e67139d095f4309b03cc686e6ec982e602eaa03fec8 |