skip to Main Content

I want to create Stripe express accounts for my customers (who will receive money) on my WordPress platform. An user account will be created when the user registers on my platform. How can I do it?

I’ve installed two Stripe extensions to help me but none of those extensions allows account creation for customers. I’ve tried browsing on Stripe docs in order to write my own code. I found some examples and tried a short code for the code below after including the Stripe library folder in my theme folder.

require_once get_template_directory() . '/stripe-php-master/lib/Stripe.php';
$stripe = new StripeStripeClient('<my_stripe_secret_api_key');

$stripe->accounts->create(['type' => 'express']);

I’ve include the short code on my customers registering page, but nothing worked as expected. I expected my code to create an express account without any information (apart of the mandatory one which is the account type) to see if that code worked but nothing happened.

2

Answers


  1. Chosen as BEST ANSWER

    I finally got the account creation working on another WordPress website that I got locally (for testing) with the code below and after using "code snippets" extension for integration. You can note some errors that I corrected.

    try{
     require_once get_template_directory() . '/stripe-php-master/init.php';
        $stripe = new StripeStripeClient('<my_stripe_secret_api_key>');
    
        $account = $stripe->accounts->create([
            'type' => 'express',
            'country' => 'US',
            'email' => '[email protected]',
            'capabilities' => [
              'card_payments' => ['requested' => true],
              'transfers' => ['requested' => true],
            ]]);
    }
    

    Now, using the same process, I can't get the accounts created on the real website. I've got two types of behavior when trying.

    • First, the php code works when I just print something on the page and use the HTML dedicated snippet editor of my extension (with a checkbox for authorising php code evaluation) but when I uncomment the API call part, update the snippet the page of the site where I paste my shortcode crashes with message like "Error detected" and link for WordPress debugging.
    • Second, I used the PHP dedicated snippet editor (that doesn't offer the possibility to have a shortcode), the php code seems not to work at all(I don't even get some output on the page). When I wrote all the code (with API call) I can't even save the snippet. I get error 500.

    1. Just to double-check @NigelRen ‘s line of thought – what happens if you follow the example in the API docs exactly – and better yet, dump out responses and add a try/catch to see potential issues?
    try {
      require_once get_template_directory() . '/stripe-php-master/lib/Stripe.php';
      $stripe = new StripeStripeClient('<my_stripe_secret_api_key');
    
      // A. Use exact example from API Docs just to make sure we're not missing something
      $response = $stripe->accounts->create([
        'type' => 'custom',
        'country' => 'US',
        'email' => '[email protected]',
        'capabilities' => [
          'card_payments' => ['requested' => true],
          'transfers' => ['requested' => true],
        ],
      ]);
      echo "Response 1: ";
      var_dump($response);
    
      // B. Then switch *just* the account type and confirm the difference
      $response = $stripe->accounts->create([
        'type' => 'express',
        'country' => 'US',
        'email' => '[email protected]',
        'capabilities' => [
          'card_payments' => ['requested' => true],
          'transfers' => ['requested' => true],
        ],
      ]);
      echo "Response 2: ";
      var_dump($response);
    
    } catch (Exception $e) {
      echo "ERROR: ";
      var_dump($e->getMessage());
      die;
    }
    
    1. How are you verifying?
    2. What do you see in your Stripe account?
    3. What do you get as the result of the API call itself – or is there an exception thrown?
    4. Does the result look different from 1A. vs. 1B. above?
    5. Does the result look different from when you create an account manually?

    I hope that helps get you on the right track!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search