David LUNG
David LUNG

Reputation: 1

How can I create Stripe express accounts on WordPress?

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 \Stripe\StripeClient('<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.

Upvotes: 0

Views: 189

Answers (2)

David LUNG
David LUNG

Reputation: 1

I finally got the account creation working for the platform. You can note some errors that I corrected. I also move stripe library folder on the server.

try{
 require_once('/htdocs/wp-content/stripe-php-master/init.php');
    $stripe = new \Stripe\StripeClient('<my_stripe_secret_api_key>');

    $account = $stripe->accounts->create([
        'type' => 'express',
        'country' => 'US',
        'email' => '[email protected]',
        'capabilities' => [
          'card_payments' => ['requested' => true],
          'transfers' => ['requested' => true],
        ]]);
}catch(Exception $e){
   print($e->getMessage());
}

Thank to you all.

Upvotes: 0

Chris
Chris

Reputation: 474

  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 \Stripe\StripeClient('<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!

Upvotes: 0

Related Questions