2 回答

TA貢獻1725條經驗 獲得超8個贊
例外情況可能有所不同。但是在你的代碼中,你只是試圖趕上一個例外,那就是.但是,如果例外是另一個呢?顯然,PHP執(zhí)行流不會轉到您的捕獲塊,因此您看不到消息。在圖像中,顯示您的代碼捕獲了 。PayPal\Exception\PayPalConnectionExceptionlolPayPalHttp\HttpException
因此,您需要嘗試設置多個塊。這意味著您可以根據需要添加任意數量的異常,如下面的代碼所示:catch
public static function actionGetorder($orderId)
{
try {
// 3. Call PayPal to get the transaction details
$client = PayPalClient::client();
$response = $client->execute(new OrdersGetRequest($orderId)); //The order ID isn't valid so it will give the error
var_dump ($response->result->payer->email_address);
print "Status: {$response->result->status}\n";
} catch (PayPalHttp\HttpException $e) {
echo $e->getMessage();
} catch (PayPal\Exception\PayPalConnectionException $e) {
echo $e->getMessage();
} finally {
echo 'If no exception has already been caught, show your own custom message';
}
}
現在的問題是,您如何知道應該使用哪些例外?好吧,可以從您在塊內部使用的代碼中知道它。try {}
在這種情況下,請檢查$client->execute(new OrdersGetRequest($orderId));引發(fā)任何異常。如果這樣做,請在塊中使用它們。PayPalClient::client(); orcatch
希望這對你有所幫助!

TA貢獻1853條經驗 獲得超6個贊
我有一個路由問題到類,所以這就是代碼在yii2上的工作方式,我希望它能幫助別人:
try
{
// $orderId = base64_decode($orderId);
$client = PayPalClient::client();
$response = $client->execute(new OrdersGetRequest($orderId));
$status = $response->result->status;
$email_cliente = $response->result->payer->email_address;
if ($status != 'COMPLETED')
{
\Yii::$app->session->setFlash('error', \Yii::t("app", "problema_pago"));
return $this->redirect(['../web/pagar']);
}
}
catch (\PayPalHttp\HttpException $e) {
echo $e->getMessage();
} catch (\PayPal\Exception\PayPalConnectionException $e) {
echo $e->getMessage();
}
- 2 回答
- 0 關注
- 131 瀏覽
添加回答
舉報