SuperNinja
SuperNinja

Reputation: 1606

Chargify PHP, grab customerID

For those of you familiar with using Chargify and PHP I am trying to perform what should be a simple request. I am creating a new user using the Chargify API. This portion of my code is working. The request is being sent and Chargify is recording the new customer. What I would like to be able to do is grab the ID of the customer that was just created. This is what I am using and it's throwing error.

code

// Create a ChargifyProduct object in test mode.
        $customer->email = $_POST['email'];
        $customer->first_name = $_POST['first_name'];
        $customer->last_name = $_POST['last_name'];
        $new_customer = $customer->create();
        //Grab customer ID
        $customer_x = $new_customer->getByID();

error

Fatal error: Uncaught exception 'ChargifyConnectionException' with message 'An error occurred while connecting to Chargify: Couldn't resolve host '.chargify.com' (6)' in /home/assets/lib/ChargifyConnector.php:99 Stack trace: #0 /home/\assets/lib/ChargifyConnector.php(146): ChargifyConnector->sendRequest('/customers.xml', 'XML', 'POST', '<?xml version="...') #1 /home/assets/lib/ChargifyConnector.php(157): ChargifyConnector->requestCreateCustomer('<?xml version="...') #2 /home/assets/lib/ChargifyCustomer.php(43): ChargifyConnector->createCustomer(Object(ChargifyCustomer)) #3 /home/andfun4/photoappoint.com/register/index.php(20): ChargifyCustomer->create() #4 {main} thrown in /home/assets/lib/ChargifyConnector.php on line 99

Any insight on this would be greatly appreciated.

thanks

Upvotes: 0

Views: 352

Answers (1)

JvdBerg
JvdBerg

Reputation: 21866

The error shown comes not from the code shown!

Have a look in the code from these line, they are causing the error:

$new_customer = $customer->create();
//Grab customer ID
$customer_x = $new_customer->getByID();

As I read it, in those lines, a connection with a database is made, and the first parameter (the hostname) cannot be resolved, because it does not exixst.

Upvotes: 2

Related Questions