paypal / PayPal-PHP-SDK

PHP SDK for PayPal RESTful APIs
https://developer.paypal.com/docs/api/
Other
27 stars 99 forks source link

Phone input on the Paypal landing page won't be populated #1200

Closed Shigeki1120 closed 5 years ago

Shigeki1120 commented 6 years ago

General information

I've been trying to pre-fill a billing address on the Paypal landing page for the guest checkout. Here is the code

        $address = new Address;
        $address
            ->setLine1(session('address_line_1'))
            ->setLine2(session('address_line_2'))
            ->setCity(session('town'))
            ->setPostalCode(session('postcode_zip'))
            ->setPhone(session('phone'))
            ->setCountryCode(strtoupper(session('country')))
            ->setState(strtoupper(session('state')));

        $payer_info = new PayerInfo;
        $payer_info
            ->setFirstName(session('first_name'))
            ->setLastName(session('last_name'))
            ->setEmail(session('email'))
            ->setBillingAddress($address);

        $payer = new Payer();

        return $payer->setPaymentMethod('paypal')->setPayerInfo($payer_info);

As you can see, I am trying to set payer_info to the Payer object. However, no matter what format I use I cannot populate the phone input on the Paypal landing page. Everything else can be filled without any problems.

I have used this format +13104039128 13104039128 1 310 403 9128 +1 310 403 9128 3104039128 310 403 9128 for the phone input but no luck

Do you have any idea what's causing this issue?

P.S the phone number above is a valid U.S number, and the country and state input are pre-filled properly

Json payload

Payment {#790 ▼
  -_propMap: array:4 [▼
    "intent" => "Sale"
    "payer" => Payer {#747 ▼
      -_propMap: array:2 [▼
        "payment_method" => "paypal"
        "payer_info" => PayerInfo {#744 ▼
          -_propMap: array:4 [▼
            "first_name" => "Ken"
            "last_name" => "Mat"
            "email" => "example@gmail.com"
            "billing_address" => Address {#745 ▼
              -_propMap: array:6 [▼
                "line1" => "18215 Rayne St"
                "city" => "Northridge"
                "postal_code" => "91325"
                "phone" => "3104021296"
                "country_code" => "US"
                "state" => "CA"
              ]
            }
          ]
        }
      ]
    }
    "redirect_urls" => RedirectUrls {#788 ▼
      -_propMap: array:2 [▼
        "return_url" => "http://magenta.test/paypalstatus"
        "cancel_url" => "http://magenta.test/paypalstatus"
      ]
    }
    "transactions" => array:1 [▼
      0 => Transaction {#787 ▼
        -_propMap: array:3 [▼
          "amount" => Amount {#786 ▼
            -_propMap: array:2 [▼
              "currency" => "EUR"
              "total" => "105.00"
            ]
          }
          "item_list" => ItemList {#785 ▼
            -_propMap: array:2 [▼
              "shipping_address" => ShippingAddress {#784 ▼
                -_propMap: array:6 [▼
                  "line1" => "18215 Rayne St"
                  "city" => "Northridge"
                  "postal_code" => "91325"
                  "phone" => "3104021296"
                  "country_code" => "US"
                  "state" => "CA"
                ]
              }
              "items" => array:1 [▼
                0 => Item {#782 ▼
                  -_propMap: array:5 [▼
                    "name" => "Magenta"
                    "currency" => "EUR"
                    "quantity" => 1
                    "price" => "105.00"
                    "sku" => "Magenta"
                  ]
                }
              ]
            ]
          }
          "description" => "Magenta"
        ]
      }
    ]
  ]
}

Here is a image with the pre populated inputs with the exception of the phone input screen

prakash-gangadharan commented 5 years ago

Sample Code snippet:

    $payer = new Payer();
    $payer->setPaymentMethod("paypal");

    $item1 = new Item();
    $item1->setName('Ground Coffee 40 oz')
        ->setCurrency('USD')
        ->setQuantity(1)
        ->setSku("123123") 
        ->setPrice(7.5);
    $item2 = new Item();
    $item2->setName('Granola bars')
        ->setCurrency('USD')
        ->setQuantity(5)
        ->setSku("321321") 
        ->setPrice(2);
    // adding ShippingAddress
    $shippingAddress = new ShippingAddress();
    $shippingAddress->setRecipientName("Brian Robinson")
        ->setLine1("4th Floor")
        ->setLine2("Unit #34")
        ->setCity("San Jose")
        ->setCountryCode("US")
        ->setPostalCode("95131")
        ->setPhone("2025550110")
        ->setState("CA");

    $itemList = new ItemList();
    $itemList->setItems(array($item1, $item2));
    $itemList->setShippingAddress($shippingAddress);
    // adding shipping phone number
    //$itemList->setShippingPhoneNumber("2025550110");

    $details = new Details();
    $details->setShipping(1.2)
        ->setTax(1.3)
        ->setSubtotal(17.50);

    $amount = new Amount();
    $amount->setCurrency("USD")
        ->setTotal(20)
        ->setDetails($details);

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

    $baseUrl = "https://example.com";
    $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));

     // Create payment with valid API context
    try {
      $payment->create($apiContext);

      echo $payment;

    } catch (PayPal\Exception\PayPalConnectionException $ex) {
      echo $ex->getCode();
      echo $ex->getData();
      die($ex);
    } catch (Exception $ex) {
      die($ex);
    }

Hi @Shigeki1120 , you can try adding Shipping Address along with phone number [ using $shippingAddress->setPhone("2025550110") ] or try adding the phone number using $itemList->setShippingPhoneNumber("2025550110") method. Both the ways prefill the phone number during the guest checkout . Please refer the above code snippet and below screen shot for the reference.

Guest Flow Screenshot: image