Jump to content
  • Checkout
  • Login
  • Get in touch


The e-commerce.

Paywhirl to manage subscription payments


Recommended Posts

On our site, some pages are planned which will be accessible to visitors who make regular subscription payments. After quite a bit of research, it seems that the Paywhirl resources will be the best for us for managing subscriptions. I don't know if these changes could ever formalized into a full Add On, but I will keep a diary of the process and trouble shooting for the benefit of anyone in the future. We are integrating their solution as much as possible. Although full cart integration is not possible, our site will be storing a customer's Paywhirl credentials in our own oscommerce tables and interacting with Paywhirl through their PHP kit using webhooks and jSON objects, so that, for example, regular oscommerce log-in will be able to determine a customer's subscriber status. I've written mountains of bad PHP in my life, but some of this stuff will be new to me.

I'll try to record our progress in this thread. Also, issues may arise for which I am hoping for the assistance of others. For example, Paywhirl utilizes Composer ("a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you."). This is already installed on our server. I don't think that the oscommerce libraries rely on Composer, though I could be wrong. I am just new starting the process of learning about Composer, and I am interested to hear if anyone has encountered compatibility issues with Phoenix. Thanks!


Edited by wetzel
Link to comment
Share on other sites

Composer appears to present no issues. It's probably already on your server, though getting the path might involve a chat with your ISP.

Paywhirl has a set of instructions you use on cpanel - terminal to install the paywhirl function libraries for your project. Composer is actually pretty nifty.

$ composer require paywhirl/paywhirl

Have placed the following in application_top.php, which is the last step to being able to call paywhirl functions. It's a call to Composer then a specific call to the Paywhirl functions.



use PayWhirl\PayWhirl;

$api_key = "######################";
$api_secret = "######################";

$paywhirl = new \PayWhirl\PayWhirl($api_key, $api_secret);

I can now use paywhirl PHP methods from within the PHP in my oscommerce scripts. These methos allow you to interact with customer records, plans, and subscriptions in their database.

Anyway, this is a diary of the paywhirl pseudo-integration I am carrying out at my site to enable restricted content pages available only through subscription. If someone trying to solve a similar problem in the future, I hope this gives you some assistance.

If you read this and spot a pitfall for  Phoenix, please .make a comment. So far everything seems to be progressing well.



Edited by wetzel
Link to comment
Share on other sites

Things are moving along. Added this to create_account.php (after the new customer is inserted into DB but before the declaration of the session variables)

// create paywhirl customer

$state_name = convertState($state);

if ($state_name == 'false') {$state_name = $state;}
      $paywhirlCustomer = array('first_name' => $firstname,
    'last_name' => $lastname,
    'email' => $email_address,
    'phone' => $telephone,
    'address' => $street_address,
    'city' => $city,
    'state' => $state_name,
    'zip' => $postcode,
    'country' => $country,
    'currency' => 'USD');

// the created customer is returned as an array
$myobj = $paywhirl->createCustomer($paywhirlCustomer);

$myobj2 = $paywhirl->getCustomer($email_address);
  $objectToArray = (array)$myobj2;
  $paywhirl_id = $objectToArray['id'];

tep_db_query("UPDATE customers SET paywhirl_id = '" . $paywhirl_id . "'  where customers_id = '".(int)$customer_id ."'");

//ALSO further down in the session variable declarations:


This procedure creates a duplicate Paywhirl customer record on their database whenever an oscommerce customer is created. It then queries their database for  'id', which is the unique ID  paywhirl assigns a customer when it is created. The paywhirl ID is then put into the oscommerce 'customers' table (a new field) which then will join the two sets of records, If the customer never chooses a subscription service, the information will just reside on the Paywhirl system. But if they choose to purchase a subscription at any point, the other parts of the API will let them go directly to check-out without having to log in or register on the paywhirl system.

We'll also need to declare $paywhirl_id after regular log-in.

PS. convertState() is just a simple function that converts the state abbreviations into full state name, which is how paywhirl does it. If it's not a USA state, it should just leave it as is.

PSS. I should mention also that json_decode() does not work with the paywhirl json object, for some reason, but $objectToArray does the job.

Edited by wetzel
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...