chargify icon indicating copy to clipboard operation
chargify copied to clipboard

Grab customer_id when creating new subscription

Open darylalexjohnson opened this issue 11 years ago • 0 comments

I am using the following from your example in my application:

$customer = new ChargifyCustomer(NULL, CHARGIFY_TEST_MODE);

        // Create a ChargifyProduct object in test mode.
        $customer->email = $_POST['email'];
        $customer->first_name = $_POST['first_name'];
        $customer->last_name = $_POST['last_name'];


    $product = new ChargifyProduct(NULL, $CHARGIFY_TEST_MODE);
    $product->id = FREE_BUSINESS;

    $subscription = new ChargifySubscription(NULL, $CHARGIFY_TEST_MODE);
    $subscription->customer_attributes = $customer;

    // Uses the first exising product. Replace with a product handle string.
    $f_products = $product->getByID();

    $subscription->product_handle = $f_products->handle;
    // $subscription->customer_id = $cust_id->id;
    try {
      $new_subscription = $subscription->create();
      // $subscription_id = 
    } catch (ChargifyValidationException $cve) {
      // Error handling code.
      echo $cve->getMessage();
    }

I have been attempting several solutions to populate the $customer->id with the id created by Chargify. However anytime I attempt $customer->getByID() I am returned a fatal error from the ChargifyConnector.php. How can I get the customer ID of this newly created subscription?

Thanks

darylalexjohnson avatar Sep 07 '12 16:09 darylalexjohnson