Jump to content
Sign in to follow this  
wetzel

Paywhirl to manage subscription payments

Recommended Posts

Posted (edited)

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

Share this post


Link to post
Share on other sites
Posted (edited)

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.


```sh
$ 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.


//paywhirl

require_once('/home/#######/vendor/autoload.php');

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

Share this post


Link to post
Share on other sites
Posted (edited)

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:

tep_session_register('paywhirl_id');

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×