#littlejohn0308

1 messages · Page 1 of 1 (latest)

eternal sealBOT
short blaze
#

Sorry don't really follow your question. Could you elaborate on more details? Which Doc you are following and which code/request you have error?

shy bear
#

The parameters returned after successful payment in test mode are different from those in formal mode, and payment cannot be obtained in formal mode_ The value of intent

short blaze
#

formal mode?

#

Do you mean Live mode?

#

How different?

shy bear
#

yes live mode

short blaze
#

How different do you mean?

shy bear
#

Test mode callback has a return value, but Live mode has no return value

#

Test mode has a payload value Live mode has no value

short blaze
#

payload is what you get from your browser request to your server, so I don't think it has anything to do with Test mode or Live mode

#

You can comment out all Stripe related logic and making sure payload always get a value first

shy bear
#

public function successNotify(){

    require_once './system/stripe-php-master/init.php';
    $stripeSecretKey = $this->key();

    \Stripe\Stripe::setApiKey($stripeSecretKey);

    $payload = @file_get_contents('php://input');
    $event = null;

    try {
        $event = \Stripe\Event::constructFrom(
            json_decode($payload, true)
        );

    } catch(\UnexpectedValueException $e) {
        // Invalid payload
        http_response_code(400);
        exit();
    }
    
    switch ($event->type) {

        case 'charge.succeeded':

            $succeeded = $event->data->object;
            $srt = json_encode($succeeded);
           
            if ($succeeded->status == 'succeeded'){

                $payment_intent = $succeeded->payment_intent;
               

                $order_info = $this->db->GetOne("select * from `@#_order` where `paymentIntent_id`='$payment_intent'");
                
                

                if ($order_info['status'] != 0) {
                    return;
                }
                $money = $order_info['price'];
                $uid = $order_info['uid'];
                $sql="INSERT INTO `@#_log`(`title`,`content`)VALUES('回调返回钱','$money')";
                $this->db->Query($sql);
                $time = time();
                $this->db->Query("UPDATE `@#_order` SET `status`='1',`pay_time`='$time' where `id`='$order_info[id]'");
                $this->db->Query("UPDATE `@#_member` SET `money` = `money`+ $money WHERE `uid` ='$uid'");
            }
            break;
        default:
            echo 'Received unknown event type ' . $event->type;
    }
    http_response_code(200);
}
#

I'll send you my code to see where the problem is

short blaze
#

Oh this is webhook

#

Webhook endpoints for Live mode and Test mode are different.

#

You need different endpoints, with different secret

shy bear
#

Why did I not use the webhook key in my testing mode to successfully call back

#

What do I need to do now when using Live mode?

short blaze
#

Sorry I explained, you need diffrent webhook endpoints setup for Test mode vs Live mode
https://dashboard.stripe.com/test/webhooks
vs
https://dashboard.stripe.com/webhooks

#

When you setup another Live mode endpoint, you will need to takes its secret into your code

#
            $event = \Stripe\Event::constructFrom(
                json_decode($payload, true)
            );

This part doesn't look correct to me btw

shy bear
#

Hello, I have tested it. The test endpoint has parameter returns, but the Live endpoint has no parameter returns.

#

$event = \Stripe\Event::constructFrom(
json_decode($payload, true)
);

#

May I ask how is it correct?

short blaze
#

ie. in the Doc above it should have the endpoint secret

try {
    $event = \Stripe\Webhook::constructEvent(
      $payload, $sig_header, $endpoint_secret
    );
  }
shy bear
#

Okay, I'll give it a try

#

Does Payload not require JSON format?

#

json_decode($payload,true)

#

Still not correct

shy bear
#

Are you still there? I need your help

short blaze
#

Yes, I would recommend download the whole code example from above Doc

#

and run it first

shy bear
#

Is this correct?

short blaze
shy bear
#

I have already tried it. The test mode is okay, but the Live mode is not

short blaze
#

Did you update the Live mode endpoint secret into line 10?

shy bear
#

yes

short blaze
#

Okie, and do you observe your Live mode events come in?

#

Can you post here the Live mode event id? evt_xxx

shy bear
#

Yes, the Live mode can successfully pay now, but it cannot return to a successful status. Can you understand what I mean?

#

The Live mode allows for normal payment, and the credit card displays pre authorization deduction, but the interface did not return success parameters to me and cannot be recalled.

#

evt_3NOEzIJ11z4DgEya1R9O8SLc

short blaze
#

Looking at the event I see your server returns 500 error

shy bear
short blaze
#

Oh sorry yes you need both constructFrom and constructEvent

#

And yes secret is the one on the left, which has the format of whsec_xxx

#

and we_xxx on the right is not sig_header. sig_header comes from HTTP_STRIPE_SIGNATURE

eternal sealBOT
short blaze
#

But really you want to look at your server log and see where does it return 500

shy bear
#

HTTP_ STRIPE_ Where to obtain the signature

spring forge
shy bear
#

I couldn't find HTTP_ STRIPE_ Signature

spring forge
#

What do you mean 'couldn't find'? What have you tried?

shy bear
#

Can you sapeak chinese

spring forge
#

No, we can only offer English support here. If you need non-English support, please write in: https://support.stripe.com/contact

shy bear
#

$sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE'];

#

Is that right?

spring forge
#

Yep, should be if you're using PHP

shy bear
#

wow It has been resolved, thank you