Laravel - PayPal поддерживает превышение максимум на 30 секундPhp

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 Laravel - PayPal поддерживает превышение максимум на 30 секунд

Сообщение Anonymous »

Paypal в laravel продолжает возвращать тайм-аут максимум 30 секунд, иногда все может работать гладко, но при увеличении количества товаров в корзине он будет продолжать возвращать эту ошибку, и иногда ошибка возникает при создании платежа, иногда при выполнении платежа, крайне не стабильно, как могу ли я решить это? я попытался увеличить значение тайм-аута до 300, но мне все равно выдается ошибка тайм-аута.

вот мой код создания платежа:
$item_array = [];
$shipping = $request->shipping;
$tax = $request->tax;
$tax_amount = 0;
$subtotal = $total = 0;
$currency = "MYR";
$payer = new Payer();
$payer->setPaymentMethod("paypal");
$credential = new OAuthTokenCredential(env('PAYPAL_SANDBOX_CLIENT_ID'), env('PAYPAL_SANDBOX_SECRET'));
$apiContext = new ApiContext($credential, null);
$order = Order::findOrFail($id);
// change order product status
foreach ($order->orderProduct as $order_product_key => $order_product) {
// get variant
$variant_title_array = array();
if (count($order_product->variantValue) > 0) {
foreach ($order_product->variantValue->variantOption as $variant_option) {
array_push($variant_title_array, $variant_option->name);
}
}

$variant= "";
if (count($variant_title_array) > 0) {
$variant = " ( ".implode(', ', $variant_title_array)." )";
}

// calculate product price and promotion price
$product_price = $compare_price = "";
$product_promotion = get_cart_product_promotion ($order_product, $order);

$product_price = get_product_price_in_cart ($order_product);

// if promotion exits
if (count($product_promotion) != 0) {
$compare_price = get_product_price_in_cart ($order_product);

$product_price = calculate_product_price_after_promotion ($compare_price, $product_promotion);
}

$item = new Item();
$item->setName($order_product->product->title . $variant)
->setCurrency($currency)
->setQuantity($order_product->quantity)
->setSku(get_product_sku_in_cart ($order_product)) // Similar to `item_number` in Classic API
->setPrice((float) str_replace('RM ','', $product_price));
$item_array[$order_product_key] = $item;
$subtotal += (float) str_replace('RM ','', $product_price) * $order_product->quantity;
}

// calculate tax
$tax_amount = ($subtotal * $tax) / 100;

$itemList = new ItemList();
$itemList->setItems($item_array);

$shipping_address = new ShippingAddress();

$shipping_address->setCity('City')
->setCountryCode('AR')
->setPostalCode('200')
->setLine1('Adress Line1')
->setState('State')
->setRecipientName('Recipient Name');

$details = new Details();
$details->setShipping($shipping)
->setTax($tax_amount)
->setSubtotal($subtotal);

$total = $subtotal + $shipping + $tax_amount;
$amount = new Amount();
$amount->setCurrency($currency)
->setTotal($total)
->setDetails($details);

$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($itemList)
->setDescription("Payment description")
->setInvoiceNumber(uniqid());

$baseUrl = url('/');
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("$baseUrl/ExecutePayment.php?success=true")
->setCancelUrl("$baseUrl/ExecutePayment.php?success=false");

$payment = new Payment();
$payment->setIntent("sale")
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions(array($transaction));

$request = clone $payment;

try {
$payment->create($apiContext);
} catch (PayPalConnectionException $ex) {
echo $ex->getCode(); // Prints the Error Code
echo $ex->getData(); // Prints the detailed error message
die($ex);
} catch (Exception $ex) {
die($ex);
}

$approvalUrl = $payment->getApprovalLink();

$response = array(
'paymentID' => $payment->id
);

return json_encode($response);


вот мой код выполнения платежа:

$shipping = $request->shipping;
$tax = $request->tax;
$tax_amount = 0;
$subtotal = $total = 0;
$currency = "MYR";

$credential = new OAuthTokenCredential(env('PAYPAL_SANDBOX_CLIENT_ID'), env('PAYPAL_SANDBOX_SECRET'));
$apiContext = new ApiContext($credential, null);
$paymentId = $request->paymentID;
$payment = Payment::get($paymentId, $apiContext);

$transaction = new Transaction();
$amount = new Amount();
$details = new Details();

$order = Order::findOrFail($id);

// store order address
$order_address = OrderAddress::firstOrCreate(
[
'order_id' => $order->id
],
[
'name' => $request->shipping_name ,
'phone' => $request->shipping_phone ,
'address1' => $request->shipping_address1 ,
'address2' => $request->shipping_address2 ,
'postcode' => $request->shipping_postcode ,
'state' => $request->shipping_state ,
'country' => $request->shipping_country ,
'city' => $request->shipping_city ,
'order_id' => $order->id
]
);

// update address if exist
$order_address->update([
'name' => $request->shipping_name ,
'phone' => $request->shipping_phone ,
'address1' => $request->shipping_address1 ,
'address2' => $request->shipping_address2 ,
'postcode' => $request->shipping_postcode ,
'state' => $request->shipping_state ,
'country' => $request->shipping_country ,
'order_id' => $order->id
]);

// change order product status
foreach ($order->orderProduct as $order_product) {

// calculate product price and promotion price
$product_price = $compare_price = "";
$product_promotion = get_cart_product_promotion ($order_product, $order);

$product_price = get_product_price_in_cart ($order_product);

// if promotion exits
if (count($product_promotion) != 0) {
$compare_price = get_product_price_in_cart ($order_product);

$product_price = calculate_product_price_after_promotion ($compare_price, $product_promotion);
}

$product_price = (float) str_replace("RM ","",$product_price);

// add promotion to order product if promotion exist
if ($compare_price != "") {
$order_product->order_promotion_id = $order->orderPromotion->promotion_id;
}

$order_product->price = $product_price;
$order_product->status = 2;

$subtotal += $product_price * $order_product->quantity;

$order_product->save();
}

// calculate tax
$tax_amount = ($subtotal * $tax) / 100;

// change cart detail
$current_date_time = Carbon::now();
$order->update([
'subtotal' => $subtotal,
'status' => 2,
'submited_on' => $current_date_time,
'payment_method' => "paypal"
]);

// update shipping fees
if ($shipping > 0) {
$order->shipping_fees = $shipping;
}

// update tax
if ($tax > 0) {
$order->tax = ($subtotal * $tax) / 100;
}

$order->save();

// paypal settings
$total = $subtotal + $shipping + $tax_amount;

$details->setShipping($shipping)
->setTax($tax_amount)
->setSubtotal($subtotal);
$amount->setCurrency($currency);
$amount->setTotal($total);
$amount->setDetails($details);
$transaction->setAmount($amount);
// Add the above transaction object inside our Execution object.
$execution->addTransaction($transaction);

try {

$result = $payment->execute($execution, $apiContext);

try {
$payment = Payment::get($paymentId, $apiContext);
} catch (Exception $ex) {

exit(1);
}
} catch (Exception $ex) {

exit(1);
}

echo "success";


Подробнее здесь: https://stackoverflow.com/questions/478 ... ond-exceed
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»