#cyberbyte_code

1 messages ยท Page 1 of 1 (latest)

mint spruceBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1222905926743232775

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

hidden sinewBOT
#

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

runic shadow
#

Hello

jovial yoke
#

Hi @runic shadow

#

I'm stuck

runic shadow
#

Can you explain more what you mean here?

#

I don't really understand what you are trying to do based on the above

jovial yoke
#

is it possible to have a call?

#

so I can screenshare

runic shadow
#

No we can only use chat here

jovial yoke
#

okey, I'll share screenshots and snippets then

runic shadow
#

Yep that's the best thing to do

#

But first just start with an overall explanation of what you are trying to do

jovial yoke
#

I'm setting up a online store for someone, and I'm having issues confirming the payment before moving forward

runic shadow
#

Okay. And you are confirming server-side?

#

And what does "moving forward" entail?

jovial yoke
#

so, first step is when you sign up, you need to pay for a subscription, and in order to register the user in the database, I need to confirm the payment was complete first

runic shadow
#

Okay sure

jovial yoke
#

is it possible to do this without using webhook, or do I need to use webhook?

runic shadow
#

That depends. Are you collecting the customers payment method ahead of starting this Subscription or upon the initial payment?

#

Overall you are going to need Webhooks regardless with Subscriptions

#

And you really should use them here as well

jovial yoke
#

okey, in that case. First, I'm using embedded form for all purchases

runic shadow
#

Embedded form meaning Embedded Stripe Checkout?

jovial yoke
#

I'm using php and javascript btw

#

this is what I've done on the test-server, and it's working

require_once 'vendor/autoload.php';

if (!isset($_SESSION['p'])) {
    echo json_encode(array('error' => 'Invalid data provided'));
    exit();
} else {
    $priceCode = $_SESSION['p'];
}

$YOUR_DOMAIN = 'http://dev.skybyn.no/smietarot';

$stripe = new \Stripe\StripeClient($stripeSecretKey);
header('Content-Type: application/json');

$checkout_session = $stripe->checkout->sessions->create([
    'ui_mode' => 'embedded',
    'line_items' => [[
        'price' => "price_1Oyi1QEFeu1ksCMiKVehgGdw",
        'quantity' => 1,
    ]],
    'mode' => 'subscription',
    'return_url' => $YOUR_DOMAIN . '/bli-medlem?betalt',
]);

$price = $stripe->prices->retrieve(
    $priceCode,
    []
);
$priceAcmount = $price->unit_amount;
$priceCurrency = $price->currency;
$priceMethods = $price->payment_methods;
$paymentIntent = $stripe->paymentIntents->create([
    'amount' => $priceAcmount,
    'currency' => $priceCurrency,
    'automatic_payment_methods' => ['enabled' => true],
]);
$paymentIntentId = $paymentIntent->id;
$receiveIntent = $stripe->paymentIntents->retrieve(
    $paymentIntentId,
    []
);
$paymentStatus = $stripe->paymentIntents->confirm(
    $paymentIntentId,
    [
      'payment_method' => 'pm_card_visa',
      'return_url' => $YOUR_DOMAIN,
    ]
);

$_SESSION['signup_paymentStatus'] = $paymentStatus->status;

echo json_encode(array('clientSecret' => $checkout_session->client_secret));```
runic shadow
#

Yeah you are confusing things a bit here

#

You don't confirm the PaymentIntent yourself when using a Checkout Session

#

That is all done for you

jovial yoke
#

I know that, but I need to send the intent id to confirm the status before going to the next step

runic shadow
#

Why?

jovial yoke
#

in order for the website to know the payment was successful, I need something to confirm with

jovial yoke
runic shadow
#

Yeah but you don't need the PaymentIntent at all

jovial yoke
#

that may be, so correct me please ๐Ÿ™‚

runic shadow
#

Then you also want to use Webhooks for the actual provisioning

#

You listen for customer.subscription.updated to know the status of the Subscription

#

When it moves to active then you provision

jovial yoke
#

Sorry, I don't understand

#

the session status?

#

I'm new to 3rd party codes, so please be specific with me ๐Ÿ˜…

runic shadow
#

Yes, the Checkout Session's status. In your code that would be $checkout_session -> status

jovial yoke
#

yes?

runic shadow
#

Ah it doesn't look like you are adding the {CHECKOUT_SESSION_ID} URL param to your return_url

#

That is likely why you are confused

jovial yoke
#

when I navigate to the checkout.php file, and echo the $checkout_session -> status I get "open"

runic shadow
#

Right that is because the Session hasn't been completed yet.

#

Once completed, there is a redirect to your return URL

jovial yoke
#

how so?

runic shadow
#

Have you tested this out yet?

jovial yoke
#

{CHECKOUT_SESSION_ID} you mean?

runic shadow
#

Yeah, see the example at the link above. It would look like 'return_url' => 'https://example.com/checkout/return?session_id={CHECKOUT_SESSION_ID}',

#

Then your return URL will contain the Checkout Session ID as a URL param

#

Which you can grab and use to show a confirmation page

jovial yoke
#

sure, but how do I use that id to confirm anything?

runic shadow
#

Well you can check the status of the Checkout Session or retrieve whatever information you want using that ID

#

But really, if they make it to your return URL then the session was successful

jovial yoke
#

so, by using the session id, the session will automatically close?

runic shadow
#

No that happens by default on completion. The Session ID is what you can use to get specific information client-side about that Checkout Session

#

Have you tested out completing a Checkout Session on your page yet?

jovial yoke
#

as long as you're providing the stripe script tag on the page

runic shadow
#

To see what happens?

jovial yoke
#

I have, with the code I provided before, it's working

#

this is the code I'm using on the signup page


        // Redirect to another page or perform further actions
        echo "<script>window.location.replace('bli-medlem?betaling');</script>";
        exit();
    }
    
    if (isset($_GET['betalt'])) {
        $paymentStatus = $_SESSION['signup_paymentStatus'];
        if ($paymentStatus == "succeeded") {}
    }```
runic shadow
#

Okay let's pause and backup. I think we are confusing things here a bit.

#

Your question primarily is how to know when a Subscription is activated so you know to provision your product, right?

jovial yoke
#

no, my question is to know how to verify a payment has been completed successfully

runic shadow
#

Okay really those things are synonymous. But the simple answer is that whenever your return URL is hit, the payment was completed.

#

If you are using async payment method types (like bank debits), then you would need to wait for a payment_intent.succeeded Event to know that the payment was actually successful, which can take a few days with these async payment method types.

jovial yoke
#

okey, so the payment itself can take days before it's successful?

hidden sinewBOT
runic shadow
#

For async payment methods (like bank debits), yes.

jovial yoke
#

what if.. let's say someone is signing up, they go through the payment and pays normally, they see the url and understand how the return url looks like. They don't really want to pay more, but still want's to get access. So they go to the payment page again later, and instead of going through the payment part, they manually navigate to the return url, with a random invalid session id, then the website thinks it's valid without confirming it, and they get the product.

runic shadow
#

Yeah that's why I said before that you only provision your product based on Webhooks

jovial yoke
#

okey, so how would I use the webhook?

runic shadow
#

You also want to do that because it is very possible that your customer completes the Checkout Session but then closes their browser and never makes it to your return URL

#

You listen for customer.subscription.updated and look at the status of the Subscription

jovial yoke
#

you'll have to identify customer to use that right?

#

how does it work with a normal payment?

stable crane
#

Hi taking over here

#

What do you mean by this question? If it's not a subscription payment, you can listen for payment_intent.succeeded

jovial yoke
#

btw, I'm not uing webhook, because I don't understand how to use it

#

@stable crane I mentioned my code before you came in, want me to share again?

stable crane
#

My question is what did you mean by this?

you'll have to identify customer to use that right?
how does it work with a normal payment?```
jovial yoke
#

that I'm falling off, I don't understand it

#

and that using customer.subscription.updated is for subscriptions, what about payment

stable crane
#

Have you read our webhook docs

#

It's payment_intent.succeeded

#

As I said before

jovial yoke
#

I'm not sure if I should ask you about this, but how do I use the webhook.php?

stable crane
#

Are you a developer?

jovial yoke
#

yeah, but don't feel like it right now ๐Ÿคฃ

stable crane
#

It's ok

#

Recommend reading that whole doc though

#

Have you already done that?

#

It should be a bit more clear if you read it in its entirety

#

Specifically that second link I shared

jovial yoke
#

okey

#

the docs is talking about all the different codes in so much details, and the snippets are fine, but I don't understand any of it

stable crane
#

What don't you understand

jovial yoke
stable crane
#

What do you mean

#

It's just an endpoint on your server

jovial yoke
#

to confirm the payment was complete

stable crane
#

It needs to be deployed

#

Can you be more specific?

jovial yoke
#

deployed? with CLI?

stable crane
#

Yeah a webhook endpoint needs to be live. On your server

#

However

#

I don't know what server/cloud environment you're using

#

So I can't advise there

#

I can help with Stripe questions

jovial yoke
#

I'm using a dedicated home-hosted server for testing, but the website does not have this available, as far as I've checked

stable crane
#

The doc I shared shows you how to test locally at home without deploying in test mode

jovial yoke
#

all I want to do, is use the API's to check the status of the payment by it's id to confirm that it's been successful in order to update the database for the client

stable crane
#

So you don't want to use webhooks?

jovial yoke
#

if possible, not at all

stable crane
#

Ok

#

It's not recommended

#

Your integration won't be very robust

#

But that's your choice

jovial yoke
#

okey, tell me

stable crane
#

That's your endpoint

jovial yoke
#

yes, this is what I've tried, and it's working on test server, but not on live environment

stable crane
#

What isn't working

#

I need specifics

jovial yoke
#

of course

#

this is the code I've been using:

header('Content-Type: application/json');

$checkout_session = $stripe->checkout->sessions->create([
    'ui_mode' => 'embedded',
    'line_items' => [[
        'price' => "price_1Oyi1QEFeu1ksCMiKVehgGdw",
        'quantity' => 1,
    ]],
    'mode' => 'subscription',
    'return_url' => $YOUR_DOMAIN . '/bli-medlem?betalt',
]);

$price = $stripe->prices->retrieve(
    $priceCode,
    []
);
$priceAcmount = $price->unit_amount;
$priceCurrency = $price->currency;
$priceMethods = $price->payment_methods;
$paymentIntent = $stripe->paymentIntents->create([
    'amount' => $priceAcmount,
    'currency' => $priceCurrency,
    'automatic_payment_methods' => ['enabled' => true],
]);
$paymentIntentId = $paymentIntent->id;
$receiveIntent = $stripe->paymentIntents->retrieve(
    $paymentIntentId,
    []
);
$paymentStatus = $stripe->paymentIntents->confirm(
    $paymentIntentId,
    [
      'payment_method' => 'pm_card_visa',
      'return_url' => $YOUR_DOMAIN,
    ]
);

$_SESSION['signup_paymentStatus'] = $paymentStatus->status;```
#

BUT, the 'pm_card_visa' is only for test environments

#

and to get this working live, I need that part

stable crane
#

Why do you create a checkout session and a payment intent?

#

You really should only need one or the other

jovial yoke
#

how do I get the payment_intent_id without the first one?

stable crane
#

Are you wanting to create 2 payments?

#

I'm just confused why you have checkout and payemnt intent

#

Checkout sessions generate payment intents themself

jovial yoke
#

I thoguht so, but I was getting error messages when I tried only that, let me try again

#

so what would the code need to be?

stable crane
#

Let's slow down here. One step at a time. What are you building? How many payments are you trying to accept

jovial yoke
#

an online store, one payment at the time

#

really simple

#

I thought ๐Ÿคฃ

stable crane
#

So why is your checkout session in subscription mode?

#

'mode' => 'subscription',

jovial yoke
#

yes, because the signup is a subscription, the products are payment

stable crane
#

What does that mean

jovial yoke
#

you can sign up, and the registration is a membership, the membership is a subscription. but the website also has products that are normal payments

stable crane
#

Ah ok

#

So the customer checks out once and buys a subscription

#

Then they can optionally check out again and buy products?

jovial yoke
#

yes

stable crane
#

And the code you shared with me is just supposed to be the subscription piece?

jovial yoke
#

yes

#

for starters

stable crane
#

Gotcha. And you want to use embedded checkout, correct?

jovial yoke
#

correct

#

I AM using embedded ๐Ÿ˜„

#

so all I need to know/understand, is what codes I need to use to confirm the payment for each checkout

stable crane
#

You don't need to confirm it

#

The customer does that by clicking the pay button

#

That's the advantage of embedded checkout

#

The stripe-hosted portion handles most everything

jovial yoke
#

yeah, but in order to update the database for the website I need to verify, right?

stable crane
#

Yeah I hate to tell you, that's what webhooks are for

#

Webhooks would be the easiest in this flow I'm afraid

jovial yoke
#

I get that, but if I am unable to use webhooks, what then?

#

I'm stuck?

stable crane
#

Kinda. You could have code built around your return url

#

But that's very risky

#

Customer may never reach it

#

Or customers could find out that all they have to do to have access provisioned is reach your return url

jovial yoke
stable crane
#

It's not a very good coding practice at all

#

I mean provision access to them once they reach the return url from Checkout

#

But that's super insecure and risky

#

Have you tried webhooks?

#

Have you read that entire guide I sent you?

jovial yoke
#

I've tried webhooks yes, but not a way I am comfortable with ๐Ÿ˜…

jovial yoke
#

I'll need my partner to do this

#

so there are no way except webhooks to check if a payment was successful after a checkout using api?

stable crane
#

No

#

You can use return url like I said

#

I'm just saying that it's HIGHLY not recommended

#

You'll likely run into tons of issues once you go live

#

With some folks not having subscriptions provisioned

#

I recommend you build it right once tbh

jovial yoke
#

got it

#

okey, thanks

#

so in order for a webhook to work, you'll need to deploy a terminal to send and/or receive the data right?

stable crane
#

I don't know what deploy a terminal means

#

You just need a webhook endpoint available at a public url

jovial yoke
#

what do you mean by "deploy"?

stable crane
#

?

#

You said deploy

#

What does that mean

#

like i have no idea what you mean by deploy a terminal

#

You just need an endpoint on your server that's publicly reachable by us to send events to

jovial yoke
stable crane
#

Referring to your server, yes

#

That's standard terminology in software dev for pushing a website/server to production

jovial yoke
#

okey, so a public web address that can be used as an api?

stable crane
#

It won't be a webpage

#

It's just exposing an endpoint on your server for POST requests only

#

That we can reach

jovial yoke
#

okey, sure, I think we speak in different languages, but I'm starting to understand now ๐Ÿคฃ

#

so this webhook, it's like the example provided on your docs page, used to receive post requests and return some data right?

stable crane
#

I'm using standard terminology for the industry/software dev

jovial yoke
#

great, that's also how an api works, so we're good

stable crane
#

It is an api

#

It's an api endpoint that we, Stripe, hit on your server

jovial yoke
#

yes, I've figured that now, so how would I set this webhook up for the payment confirmation to work?

stable crane
#

Have you read the docs I sent? They cover all this