#jcodog-checkout-customprice

1 messages · Page 1 of 1 (latest)

upper peak
#

Hey @hallow pier you control the creation of the Session so yes, you can create a Price for the right amount and pass that

hallow pier
#

The price is already set

#

I want to modify the default value they see when they get redirected to the checkout so they can pay right away, or change the amount at checkout if they change their mind.

#

The documentation only says I can change the quantity?

upper peak
#

I don't understand what you call the default value and what price is already set

#

you can't change a Session. You need to create the Session after they choose how much to pay

hallow pier
#

This is where they pick the amount they want to pay, but the product it uses is allowing for them to change the amount to pay only in the checkout itself

upper peak
#

sure but that's just your UI

#

create the Session after they click on the Donate

hallow pier
#

It just sends me here, I cannot figure out how to change what it shows there, while creating the session

upper peak
#

I'm sorry, you still only give half of the info I'm after

hallow pier
#

hold on, let me get it from the dashboard.

upper peak
#

Are you using PaymentLinks?

hallow pier
#

No

#

But the product I use lets users change the amount to pay within the checkout

#

And I am trying to modify the default amount before it goes to checkout

upper peak
#

yeah that's impossible

hallow pier
#

So I cannot allow them to use a slider before they get to the checkout to modify it?

upper peak
#

correct you can't

#

not unless you create a separate Price for this and set a different preset each time, which isn't really worth the trouble

hallow pier
#

Yes I can see why that would be unwise, I could maybe get around it using quantities on a £1 price and avoid this price entirely?

upper peak
#

you could, I wouldn't. I'd remove the slider entirely and let them change the amount on Checkout

hallow pier
#

Ok I just wanted to make the UI look better for them and match how other services that take donations work.

#

Thanks for your help.

upper peak
#

sure!

hallow pier
#
Warning: Undefined variable $cutomer in /donate/return.php on line 73
Warning: Attempt to read property "invoice_settings" on null in /donate/return.php on line 73
Warning: Attempt to read property "default_payment_method" on null in /donate/return.php on line 73
Warning: Undefined variable $checkout in /home/u201085483/domains/jconet.co.uk/public_html/donate/return.php on line 100
Warning: Attempt to read property "customer" on null in /donate/return.php on line 100
Warning: Undefined array key 0 in /donate/return.php on line 110
Warning: Trying to access array offset on value of type null in /donate/return.php on line 110
Fatal error: Uncaught Error: Undefined constant "console" in /donate/return.php:126 Stack trace: #0 {main} thrown in /donate/return.php on line 126``` I am getting this when the payment is completed on the single item for customer decides pricing. This has been a live option for some time because it didnt error before, but I am not getting errors for this and not the subscriptions.
#

@steady star

steady star
#

The error says Undefined constant "console" in /donate/return.php:126 , did you check you code in line 126?

hallow pier
#

The issue is before that

#

The warnings are what I am concerned about, console is for troubleshooting.

#

It isnt on the live server that my customer pointed the issue out in

steady star
#

Do you have the code? we can look at it together.

hallow pier
#
<?php
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);
    
    $upOne = dirname(__DIR__, 1);
    require $upOne.'/resources/vendor/autoload.php';
    $envDir = $upOne.'/resources/includes';
    Dotenv\Dotenv::createImmutable($envDir)->load('./env');


    $status = $_GET['status'];
    $type = $_GET['type'];

    $conn = mysqli_connect(dbHost,dbUser,dbPass,dbName);

    use Stripe\Stripe;

    $key = $_ENV['STRIPETESTKEY'];
    \Stripe\Stripe::setApiKey($key);
    $stripe = new \Stripe\StripeClient($key);

    if (isset($_GET['session_id'])) {
        $sessionID = $_GET['session_id'];

        $retrieved = $stripe->checkout->sessions->retrieve($sessionID, [
            'expand' => [
                'payment_intent',
                'customer'
            ]
        ]);
        $custID = $retrieved->customer->id;
        $customer = $retrieved->customer;
        $paymentMethod = $retrieved->payment_intent->charges->data->payment_method_details;
        $defaultPaymentMethod = $cutomer->invoice_settings->default_payment_method;

        if ($defaultPaymentMethod == null) {
            $stripe->customers->update(
                $custID, [
                    'invoice_settings' => [
                        'default_payment_method' => $paymentMethod
                    ]
                ]
              );
        }

        $result = mysqli_query($conn, "SELECT * FROM customers WHERE ID ='".$_SESSION['userID']."'");
        $num_rows = mysqli_num_rows($result);
        $customerDB = mysqli_fetch_all($result, MYSQLI_ASSOC);

        if ($num_rows == 0) {
            $sql2 = "insert into customers set ID='".$_SESSION['userID']."', stripeID='".$custID."'";
            mysqli_query($conn, $sql2);
        }
    }
    
    if (isset($_GET['session_id'])) {
        $sessionID = $_GET['session_id'];
        if ($type == 'CUSTOMDONATE') {
            $retrieved = $stripe->checkout->sessions->retrieve($sessionID, ['expand' => ['payment_intent']]);
            $total = $retrieved->payment_intent->amount;
            $custID = $checkout->customer;
    
            if ($total/500 > 0){
                $multiplier = $total/500;
                define('credits', 1000*$multiplier);
            }
            
            $result = mysqli_query($conn, "SELECT ID FROM customers WHERE stripeID ='".$custID."'");
            $customerDB = mysqli_fetch_all($result, MYSQLI_ASSOC);
    
            $balResult = mysqli_query($conn, "SELECT * FROM credits WHERE userID ='".$customerDB[0]['ID']."'");
            $num_rows = mysqli_num_rows($balResult);
            $creditDB = mysqli_fetch_all($balResult, MYSQLI_ASSOC);
    
            if ($num_rows > 0) {
              // update
              console.log("Update.");
              $bal = $creditDB[0]['creditBalance']+credits;
              console.log("newbal: ".$bal.".");
              if(mysqli_query($conn, "UPDATE credits SET creditBalance=".$bal." WHERE userID=".$customerDB[0]['ID'])) {
                console.log("Update completed successfully.");
              } else {
                console.log("Update failed.");
              };
            } else {
              // insert
              console.log("Insert");
              if(mysqli_query($conn, "INSERT INTO credits SET userID=".$customerDB[0]['ID'].", creditBalance=".credits)) {
                console.log("Insert completed successfully.");
              } else {
                console.log("Insert failed.");
              };
            }
        }
    }
?>```I have swapped this to test mode for now.
steady star
#

Hmm, I don't think console.log is available in PHP.

hallow pier
#

I think I messed that up, but its not relevant to the code

#

evt_1Lrty3EOJsqRXL0R2SfGd7x8

#

This is the payment that triggers all the errors

steady star
#

Did the error occur in webhook handling? do you have the relevant code?

hallow pier
#

No the webhook was errored for the live endpoint being used not the test one

#

The error is to do with retrieving the data from the checkout session in the code I send

hallow pier
steady star
#

Can you send me the relevant error message and the line that causes the error?

hallow pier
#

Warning: Attempt to read property "payment_method_details" on array in /home/u201085483/domains/jconet.co.uk/public_html/donate/return.php on line 72

Warning: Undefined variable $cutomer in /home/u201085483/domains/jconet.co.uk/public_html/donate/return.php on line 73

Warning: Attempt to read property "invoice_settings" on null in /home/u201085483/domains/jconet.co.uk/public_html/donate/return.php on line 73

Warning: Attempt to read property "default_payment_method" on null in /home/u201085483/domains/jconet.co.uk/public_html/donate/return.php on line 73

steady star
#

These are warnings, what's the error?

hallow pier
#

That is the error

#

It is meant to update the default payment method to the payment method used if one isnt set

#

It isn't retrieving the payment intent from the checkout session

#

How do I hide the line 72 error as i need it to show the payment method details, but it says attempt to read value on array

steady star
#

Again these are warnings, not errors. The compiler tells you that certain property could be null, so you should do a null check before attempting to read the property.

hallow pier
#

ah ok thanks.

#

i guess isset() then?

steady star
#

Yes you are use this function

hallow pier
#

This will get rid of the warning?

steady star
#

You need to test out by yourself.

hallow pier
#

Yep worked, thanks.