Here's the code for Cybersource SOAP Refunds

Greg's picture

This is a bit of the code I was discussing earlier for refunds through Cybersource. It only works with SOAP for now so keep that in mind. You're free to modify the code, but if you do something interesting, please post it back here in the comments! :)

Download the Cybersource Refund SOAP module Here

Here's the writeup from the module file:

// A quick and dirty module for processing 
//    Cybersource SOAP refunds.
//
// Author: Greg Eisenman
// Date: 5/23/09
//
// Requirements:uc_cybersource module enabled
//		 
//              SOAP must be enabled and              
//              correctly configured in 
//              uc_cybersource
//		 
//              Drupal 6.x/Ubercart 2.x
//			
// Features:	Processes credit card refunds 
//              through SOAP
//			
//              Limited input checking: not 
//              zero, not blank, not > order
//              total
//			
//              Limited messaging: displays 
//              reply object upon rejection, 
//              prints admin comment upon 
//              success
//			
//              Displays form on admin order 
//              view
//			
// To Do:	User Permissions
//		
//              More robust error reporting
//		
//              DOES NOT work with Silent 
//              Order POST
//		
//              Perhaps add a line item for 
//              the refund (need use case)
//			
//              Currently allows user to 
//              process more than 1 refund 
//              p/order (is this desirable?)
//			
//              Create a record of refund 
//              other than an admin 
//              comment	

Download it from the link above, enable it like you would any other module, and you're good to go.

If you have any questions, please leave a comment here.

If you want this posted to drupal.org, please contact me and I'll see what I can do. It should probably be made a little more robust before it's added there.

We're using this on a production site right now so it does work well for our needs.

If you need paid customization or help, please use the email link on the right and I'd be happy to help. My rates are reasonable.

AttachmentSize
cybersource_refund_soap.zip2.76 KB

Refund Values

Greg, thanks for much for posting this. I am using a bit of a variation from Ubercart, so I am not calling it through the UC API, but want to call your refund function directly.

cybersource_refund_soap_refund($order_id, $refund_amount, $comment, $req_code, $ref_token).

What are the $req_code and $ref_token used for?

Can I set $req_code manually to some refund code. I can't find that cybersource documentation for the SOAP API anywhere.

Thanks again.
Greg Holsclaw

Explanation of $req_code, $ref_token

Hi Greg,

Those are somewhat poorly named, and yeah, finding the right documentation can be a bit of a pain.

First, here's the guide with a list of fields required for the transaction (the fields we are interested appear starting on page 188):

http://apps.cybersource.com/library/documentation/dev_guides/CC_Svcs_IG/...

So, here's what we're doing with those two particular fields:

$request->captureRequestToken = $ref_token;
$cccredit->captureRequestID = $req_code;

And here's the explanation from Cybersource:

ccCreditService_captureRequestID:

The requestID returned from a previous
request for capture. Creates a follow-on
credit by linking the credit to the previous
capture. If you send this field, you do not
need to send several other credit request
fields.

ccCreditService_captureRequestToken:

The requestToken value returned from a
previous request for ccCaptureService. This
field is required only for follow-on credit
requests; it is not required for stand-alone
credit requests.

Essentially these fields link the credit to the order in question. As explained they are not really needed for stand alone credits, but our form is tied to order anyhow and makes the assumption that you will be refunding the order on that page.

This data is stored in the $order object like so:

$order->data['cybersource'][$req_code] = $ref_token

As you can see, I named them a bit poorly, but with the definitions above you should be able to get the idea.

Let me know if you have any questions and I'll try to explain a bit further.

If you're going to call it directly you'll need to fetch these two codes either directly from the {uc_orders} table in the DB or by doing it the Drupal way by loading the order object using uc_order_load().