Created
April 11, 2015 12:39
-
-
Save clintonb/6eb2fed53d009f31fc8b to your computer and use it in GitHub Desktop.
Issue credit via CyberSource SOAP API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This is a basic script to issue a credit via the CyberSource API. | |
Requirements: | |
suds (https://fedorahosted.org/suds/) [Install via pip] | |
References | |
* http://www.cybersource.com/developers/integration_methods/simple_order_and_soap_toolkit_api/soap_api/SOAP_toolkits.pdf | |
* http://apps.cybersource.com/library/documentation/dev_guides/CC_Svcs_SO_API/Credit_Cards_SO_API.pdf | |
* http://pydoc.net/Python/merchant-gateways/0.0.1/merchant_gateways.billing.gateways.cybersource/ | |
""" | |
import logging | |
from suds.client import Client | |
from suds.wsse import Security, UsernameToken | |
logging.basicConfig(level=logging.INFO) | |
logging.getLogger('suds.client').setLevel(logging.DEBUG) | |
merchant_id = 'edx_org' | |
url = 'https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor/CyberSourceTransaction_1.113.wsdl' | |
# Generate a SOAP Toolkit API security key at CyberSource's admin portal | |
transaction_key = 'REPLACE-ME' | |
security = Security() | |
token = UsernameToken(merchant_id, transaction_key) | |
security.tokens.append(token) | |
client = Client(url) | |
client.set_options(wsse=security) | |
# List all methods and types. One can also print other nodes (e.g. ns0:PurchaseTotals below) to view their properties. | |
print client | |
# Original CyberSource Request ID | |
order_request_token = '4286194609565000001520' | |
# Original edX order number | |
merchant_ref_code = '1428620589845' | |
credit_service = client.factory.create('ns0:CCCreditService') | |
# Tell CyberSource to activate the credit service. | |
credit_service._run = 'true' | |
# This field is required for a "follow-on" credit (e.g. credit linked to a previous transaction). | |
credit_service.captureRequestID = order_request_token | |
purchase_totals = client.factory.create('ns0:PurchaseTotals') | |
# This must be set to the same currency as the original transaction. | |
purchase_totals.currency = 'USD' | |
# This value can be whatever you'd like; however, CyberSource will not settle for any values greater than | |
# the original authorization. | |
purchase_totals.grandTotalAmount = '200.00' | |
# The orderRequestToken value is only needed for the Atos payment gateway; however, it doesn't hurt to send it | |
# with all follow-on credit requests, regardless of gateway. | |
print client.service.runTransaction(merchantID=merchant_id, merchantReferenceCode=merchant_ref_code, | |
orderRequestToken=order_request_token, ccCreditService=credit_service, | |
purchaseTotals=purchase_totals) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment