Reputation: 1
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
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
Reputation: 474
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;
}
I hope that helps get you on the right track!
Upvotes: 0