looking for some solutions? You are welcome.

SOLVED: Paypal Json and Postal code is not Invalid

Machinery State:

I'm working on paypal payment method and its working fine but when i used a valid zip code, it shows me 400 error

[{"field":"city","issue":"Value is invalid"},{"field":"state","issue":"Value is invalid"},{"field":"zip","issue":"Value is invalid"}]

I have a link in which if user enters a wrong valid postal code then its proceed to paypal checkout page, but in my scenario its show an error message.

Secondly when i'm sending payer information like email, country code etc. then it shows that Invalid json. Here is my code.

$qty = Session::get('qty');
$TotalAmount = 0;
foreach (Session::get('cart') as $index => $product) {
$price = $product->product_price;
$TotalAmount = $TotalAmount + ($price * $qty[$index]);
$item[$index] = new Item();
$item[$index]->setName($product->product_title) /** item name **/
->setCurrency('USD')
->setQuantity($qty[$index])
->setPrice($price); /** unit price **/
}
// Billing Address
$billing_address = new ShippingAddress();
$billing_address->setLine1(''.$s_line1.'');
$billing_address->setCity(''.$s_city.'');
$billing_address->setState(''.$s_state.'');
$billing_address->setPostalCode(''.$s_postalcode.'');
$billing_address->setCountryCode(''.$s_country.'');
// Payer Information
$billing_info = new PayerInfo();
$billing_info->setFirstName(''.$s_first_name.'')->setLastName(''.$s_last_name.'')->setPhone(''.$s_phone.'')->setEmail(''.$s_company_name.'')->setCountryCode(''.$s_country.'');
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$payer->setPayerInfo($billing_info);
//Create Item List Json
$item_list = new ItemList();
$item_list->setItems($item);
$item_list->setShippingAddress($billing_address);
// Create the WebProfile
$presentation = new Presentation();
$presentation->setLogoImage("https://example.com/uploads/header-logo.png")
->setBrandName("Machinery State! Paypal")
->setLocaleCode("US");
$inputFields = new InputFields();
$inputFields->setAllowNote(true)
->setNoShipping(1)
->setAddressOverride(0);
$webProfile = new WebProfile();
$webProfile->setName("ABC" . uniqid())
->setPresentation($presentation)
->setInputFields($inputFields);
$createdProfile = $webProfile->create($this->_api_context);
$createdProfileID = json_decode($createdProfile);
$profileid = $createdProfileID->id;
$amount = new Amount();
$amount->setCurrency('USD')
->setTotal($TotalAmount);
$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($item_list)
->setDescription('Your transaction description');
$redirect_urls = new RedirectUrls();
$redirect_urls->setReturnUrl(URL::route('status'))->setCancelUrl(URL::route('status'));
$payment = new Payment(); $payment->setIntent('Sale')
->setPayer($payer) ->setRedirectUrls($redirect_urls)
->setTransactions(array($transaction)) ->setExperienceProfileId($profileid);
try {
$payment->create($this->_api_context);
} catch (\Exception $ex) {
return Redirect::back()->withErrors($ex->getData())->withInput(Input::all());
}

Note: All values are dynamic and comes from database.



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
Share:

No comments:

Recent