HTML Button returning “Cannot POST /index.php”












2














I am trying to activate the index.php file which is a function for Stripe Connect. However, when I press the button on my HTML page to activate the function, it results in Cannot POST /pages/index.php. Both the HTML and PHP files are in the same folder. What I am trying to do is automate this: https://stripe.com/docs/connect/express-accounts#token-request



HTML CODE



<form action="input.php" method="post">
<input type="submit" class="bg-transparent text-grey-darkest font-bold uppercase tracking-wide py-3 px-6 border-2 border-grey-light hover:border-grey rounded-lg" value="Continue">
</form>


PHP CODE



    <?php
define('CLIENT_ID', 'ca_xxxxxxx');
define('API_KEY', 'sk_xxxxxxx');

define('TOKEN_URI', 'https://connect.stripe.com/oauth/token');
define('AUTHORIZE_URI', 'https://connect.stripe.com/oauth/authorize');

if (isset($_GET['code'])) { // Redirect w/ code
$code = $_GET['code'];

$token_request_body = array(
'client_secret' => API_KEY,
'grant_type' => 'authorization_code',
'client_id' => CLIENT_ID,
'code' => $code,
);

$req = curl_init(TOKEN_URI);
curl_setopt( $ch, CURLOPT_USERAGENT, '' );
curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
curl_setopt($req, CURLOPT_POST, true);
curl_setopt($req, CURLOPT_POSTFIELDS, http_build_query($token_request_body));

// TODO: Additional error handling
$respCode = curl_getinfo($req, CURLINFO_HTTP_CODE);
$resp = json_decode(curl_exec($req), true);
curl_close($req);

echo $resp['access_token'];
} else if (isset($_GET['error'])) { // Error
echo $_GET['error_description'];
} else { // Show OAuth link
$authorize_request_body = array(
'response_type' => 'code',
'scope' => 'read_write',
'client_id' => CLIENT_ID
);

$url = AUTHORIZE_URI . '?' . http_build_query($authorize_request_body);
echo "<a href='$url'>Connect with Stripe</a>";
}
?>









share|improve this question






















  • I think you're a little confused here. The PHP file you have there looks like it is for finalizing the OAuth connection — it's the page that you would set as the redirect_uri, which Stripe sends the user to after they authorize the connection. But when your 'Continue' button is pressed, you should actually be redirecting the customer(set window.location.href for example) to the OAuth URL, not trying to load that page.
    – karllekko
    Nov 20 at 10:34












  • Separately, you can't automate this, you need to redirect the user to the Stripe form and have them fill out the form and get redirected back to your server, that's just how Express accounts and OAuth works.
    – karllekko
    Nov 20 at 10:35
















2














I am trying to activate the index.php file which is a function for Stripe Connect. However, when I press the button on my HTML page to activate the function, it results in Cannot POST /pages/index.php. Both the HTML and PHP files are in the same folder. What I am trying to do is automate this: https://stripe.com/docs/connect/express-accounts#token-request



HTML CODE



<form action="input.php" method="post">
<input type="submit" class="bg-transparent text-grey-darkest font-bold uppercase tracking-wide py-3 px-6 border-2 border-grey-light hover:border-grey rounded-lg" value="Continue">
</form>


PHP CODE



    <?php
define('CLIENT_ID', 'ca_xxxxxxx');
define('API_KEY', 'sk_xxxxxxx');

define('TOKEN_URI', 'https://connect.stripe.com/oauth/token');
define('AUTHORIZE_URI', 'https://connect.stripe.com/oauth/authorize');

if (isset($_GET['code'])) { // Redirect w/ code
$code = $_GET['code'];

$token_request_body = array(
'client_secret' => API_KEY,
'grant_type' => 'authorization_code',
'client_id' => CLIENT_ID,
'code' => $code,
);

$req = curl_init(TOKEN_URI);
curl_setopt( $ch, CURLOPT_USERAGENT, '' );
curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
curl_setopt($req, CURLOPT_POST, true);
curl_setopt($req, CURLOPT_POSTFIELDS, http_build_query($token_request_body));

// TODO: Additional error handling
$respCode = curl_getinfo($req, CURLINFO_HTTP_CODE);
$resp = json_decode(curl_exec($req), true);
curl_close($req);

echo $resp['access_token'];
} else if (isset($_GET['error'])) { // Error
echo $_GET['error_description'];
} else { // Show OAuth link
$authorize_request_body = array(
'response_type' => 'code',
'scope' => 'read_write',
'client_id' => CLIENT_ID
);

$url = AUTHORIZE_URI . '?' . http_build_query($authorize_request_body);
echo "<a href='$url'>Connect with Stripe</a>";
}
?>









share|improve this question






















  • I think you're a little confused here. The PHP file you have there looks like it is for finalizing the OAuth connection — it's the page that you would set as the redirect_uri, which Stripe sends the user to after they authorize the connection. But when your 'Continue' button is pressed, you should actually be redirecting the customer(set window.location.href for example) to the OAuth URL, not trying to load that page.
    – karllekko
    Nov 20 at 10:34












  • Separately, you can't automate this, you need to redirect the user to the Stripe form and have them fill out the form and get redirected back to your server, that's just how Express accounts and OAuth works.
    – karllekko
    Nov 20 at 10:35














2












2








2


1





I am trying to activate the index.php file which is a function for Stripe Connect. However, when I press the button on my HTML page to activate the function, it results in Cannot POST /pages/index.php. Both the HTML and PHP files are in the same folder. What I am trying to do is automate this: https://stripe.com/docs/connect/express-accounts#token-request



HTML CODE



<form action="input.php" method="post">
<input type="submit" class="bg-transparent text-grey-darkest font-bold uppercase tracking-wide py-3 px-6 border-2 border-grey-light hover:border-grey rounded-lg" value="Continue">
</form>


PHP CODE



    <?php
define('CLIENT_ID', 'ca_xxxxxxx');
define('API_KEY', 'sk_xxxxxxx');

define('TOKEN_URI', 'https://connect.stripe.com/oauth/token');
define('AUTHORIZE_URI', 'https://connect.stripe.com/oauth/authorize');

if (isset($_GET['code'])) { // Redirect w/ code
$code = $_GET['code'];

$token_request_body = array(
'client_secret' => API_KEY,
'grant_type' => 'authorization_code',
'client_id' => CLIENT_ID,
'code' => $code,
);

$req = curl_init(TOKEN_URI);
curl_setopt( $ch, CURLOPT_USERAGENT, '' );
curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
curl_setopt($req, CURLOPT_POST, true);
curl_setopt($req, CURLOPT_POSTFIELDS, http_build_query($token_request_body));

// TODO: Additional error handling
$respCode = curl_getinfo($req, CURLINFO_HTTP_CODE);
$resp = json_decode(curl_exec($req), true);
curl_close($req);

echo $resp['access_token'];
} else if (isset($_GET['error'])) { // Error
echo $_GET['error_description'];
} else { // Show OAuth link
$authorize_request_body = array(
'response_type' => 'code',
'scope' => 'read_write',
'client_id' => CLIENT_ID
);

$url = AUTHORIZE_URI . '?' . http_build_query($authorize_request_body);
echo "<a href='$url'>Connect with Stripe</a>";
}
?>









share|improve this question













I am trying to activate the index.php file which is a function for Stripe Connect. However, when I press the button on my HTML page to activate the function, it results in Cannot POST /pages/index.php. Both the HTML and PHP files are in the same folder. What I am trying to do is automate this: https://stripe.com/docs/connect/express-accounts#token-request



HTML CODE



<form action="input.php" method="post">
<input type="submit" class="bg-transparent text-grey-darkest font-bold uppercase tracking-wide py-3 px-6 border-2 border-grey-light hover:border-grey rounded-lg" value="Continue">
</form>


PHP CODE



    <?php
define('CLIENT_ID', 'ca_xxxxxxx');
define('API_KEY', 'sk_xxxxxxx');

define('TOKEN_URI', 'https://connect.stripe.com/oauth/token');
define('AUTHORIZE_URI', 'https://connect.stripe.com/oauth/authorize');

if (isset($_GET['code'])) { // Redirect w/ code
$code = $_GET['code'];

$token_request_body = array(
'client_secret' => API_KEY,
'grant_type' => 'authorization_code',
'client_id' => CLIENT_ID,
'code' => $code,
);

$req = curl_init(TOKEN_URI);
curl_setopt( $ch, CURLOPT_USERAGENT, '' );
curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
curl_setopt($req, CURLOPT_POST, true);
curl_setopt($req, CURLOPT_POSTFIELDS, http_build_query($token_request_body));

// TODO: Additional error handling
$respCode = curl_getinfo($req, CURLINFO_HTTP_CODE);
$resp = json_decode(curl_exec($req), true);
curl_close($req);

echo $resp['access_token'];
} else if (isset($_GET['error'])) { // Error
echo $_GET['error_description'];
} else { // Show OAuth link
$authorize_request_body = array(
'response_type' => 'code',
'scope' => 'read_write',
'client_id' => CLIENT_ID
);

$url = AUTHORIZE_URI . '?' . http_build_query($authorize_request_body);
echo "<a href='$url'>Connect with Stripe</a>";
}
?>






php html curl oauth-2.0 stripe-payments






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 at 2:19









Bob Filay

111




111












  • I think you're a little confused here. The PHP file you have there looks like it is for finalizing the OAuth connection — it's the page that you would set as the redirect_uri, which Stripe sends the user to after they authorize the connection. But when your 'Continue' button is pressed, you should actually be redirecting the customer(set window.location.href for example) to the OAuth URL, not trying to load that page.
    – karllekko
    Nov 20 at 10:34












  • Separately, you can't automate this, you need to redirect the user to the Stripe form and have them fill out the form and get redirected back to your server, that's just how Express accounts and OAuth works.
    – karllekko
    Nov 20 at 10:35


















  • I think you're a little confused here. The PHP file you have there looks like it is for finalizing the OAuth connection — it's the page that you would set as the redirect_uri, which Stripe sends the user to after they authorize the connection. But when your 'Continue' button is pressed, you should actually be redirecting the customer(set window.location.href for example) to the OAuth URL, not trying to load that page.
    – karllekko
    Nov 20 at 10:34












  • Separately, you can't automate this, you need to redirect the user to the Stripe form and have them fill out the form and get redirected back to your server, that's just how Express accounts and OAuth works.
    – karllekko
    Nov 20 at 10:35
















I think you're a little confused here. The PHP file you have there looks like it is for finalizing the OAuth connection — it's the page that you would set as the redirect_uri, which Stripe sends the user to after they authorize the connection. But when your 'Continue' button is pressed, you should actually be redirecting the customer(set window.location.href for example) to the OAuth URL, not trying to load that page.
– karllekko
Nov 20 at 10:34






I think you're a little confused here. The PHP file you have there looks like it is for finalizing the OAuth connection — it's the page that you would set as the redirect_uri, which Stripe sends the user to after they authorize the connection. But when your 'Continue' button is pressed, you should actually be redirecting the customer(set window.location.href for example) to the OAuth URL, not trying to load that page.
– karllekko
Nov 20 at 10:34














Separately, you can't automate this, you need to redirect the user to the Stripe form and have them fill out the form and get redirected back to your server, that's just how Express accounts and OAuth works.
– karllekko
Nov 20 at 10:35




Separately, you can't automate this, you need to redirect the user to the Stripe form and have them fill out the form and get redirected back to your server, that's just how Express accounts and OAuth works.
– karllekko
Nov 20 at 10:35

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53385300%2fhtml-button-returning-cannot-post-index-php%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53385300%2fhtml-button-returning-cannot-post-index-php%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

If I really need a card on my start hand, how many mulligans make sense? [duplicate]

Alcedinidae

Can an atomic nucleus contain both particles and antiparticles? [duplicate]