The website currently have 2 payment options (Mada, Visa/Master). I want to add ApplePay option.
The code is using ternary operator
I want to change it to a readable if/else statement but the result gives 500 error.
The old code (working):
$data = "entityId=" . ($request->payment_option == 'hyperpay_mada' ? env('HYPERPAY_MADA_ENTITY') ? env('HYPERPAY_VISA_ENTITY') : env('HYPERPAY_APPLEPAY_ENTITY') ).
"&amount=" . str_replace(',','',number_format($order->grand_total,2)) .
"¤cy=SAR" .
"&billing.city=" .$order->city.
"&billing.state=" .$order->city.
"&billing.postcode=0000".
"&billing.country=SA".
"&customer.givenName=" .$order->name.
"&paymentType=DB" .
// "&testMode=EXTERNAL" .
"&customer.email=" . (!empty(session('shipping_info')['email']) && session('shipping_info')['email'] != 'null' && session('shipping_info')['email'] != null ? session('shipping_info')['email'] :'shopcustomer'. rand(10000, 99999).'@parduswear.com') .
"&merchantTransactionId=" . uniqid();
What I am trying to do:
function paymentMethods() {
if($request->payment_option == 'hyperpay_mada'){
env('HYPERPAY_MADA_ENTITY').
} elseif($request->payment_option == 'hyperpay_visa'){
.env('HYPERPAY_VISA_ENTITY').
} elseif($request->payment_option == 'hyperpay_applepay'){
env('HYPERPAY_APPLEPAY_ENTITY').
}
}
$data = "entityId=" . paymentMethods() .
"&amount=" . str_replace(',','',number_format($order->grand_total,2)) .
"¤cy=SAR" .
"&billing.city=" .$order->city.
"&billing.state=" .$order->city.
"&billing.postcode=0000".
"&billing.country=SA".
"&customer.givenName=" .$order->name.
"&paymentType=DB" .
// "&testMode=EXTERNAL" .
"&customer.email=" . (!empty(session('shipping_info')['email']) && session('shipping_info')['email'] != 'null' && session('shipping_info')['email'] != null ? session('shipping_info')['email'] :'shopcustomer'. rand(10000, 99999).'@parduswear.com') .
"&merchantTransactionId=" . uniqid();
I tried also adding the if statement without creating a function yet gives me the same 500 error.
Aucun commentaire:
Enregistrer un commentaire