Looking for advice on how to integrate third party library

Posts: 3
Joined: 05/07/2008

I need to integrate a third party library into Ubercart and am looking for tips on the best way to do this.

Once the payment is received, I need to make a third-party API call that asks for a key. If the request is successful, we include the key with the "file download available" email. If the request is not successful we need to handle the error appropriately (by sending a page/email/sms or something yet to be determined) and allow the transaction to continue as configured.

So, basically, I think I'm talking about creating a module that "requires" the third-party API, and then overrides uc_cart_complete_sale(). Is this the best method to do something like this? Or is there a better location to insert this type of business logic. Ideally, I'll add this to contrib when I'm done so I would like to do it right.

So, something like this (pseudo-code):

if (payment.hasBeenReceived())
  $sdk = new SDK();
  $result = $sdk->request(payload params);

  if($result === false)
    handleErrorAppropriately();
  else
    insertKeysIntoFileDownloadEmail($result['key']);

  goOnAboutYour MerryWay();

I'm a Drupal/Ubercart n00b so be gentle with me....

Posts: 3226
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

I'm not sure how you'll integrate it into the file download available e-mail, but I don't think you want to override uc_cart_complete_sale(). Perhaps you can try making the API call through a custom module w/ hook_order() on the 'submit' $op and store the key in the order's data array. Then you can define a token for the key that you can use in the e-mails...