dqzg62440 2018-05-13 16:12
浏览 233

在PayPal中,是否可以从他的电子邮件地址获取买家送货地址?

I am using PayPal Rest API, and I make PHP page that ask buyers shipping addresses and do payment.

So buyer inputs his shipping address before click 'Pay' button.

Here when doing payment, I want to compare this shipping address with buyer's PayPal shipping address. I know buyer has his shipping address in their PayPal account.

So is there any way to do this?

Maybe by getting buyer's shipping address from his email and comparing it with inputted shipping address?

Or any PayPal API option for comparing inputted shipping address with PayPal account's one?

This is my PHP Laravel code for PayPal work.

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

    $item_1 = new Item();
    $item_1->setName('Item 1') /** item name **/
        ->setCurrency('USD')
        ->setQuantity(1)
        ->setPrice(Input::get('amount')); /** unit price **/
    $item_2 = new Item();
    $item_2->setName('Item 2') /** item name **/
        ->setCurrency('USD')
        ->setQuantity(1)
        ->setPrice(20); /** unit price **/

    $shipping_address = new ShippingAddress();
    $shipping_address->setCity('San Jose');
    $shipping_address->setCountryCode('US');
    $shipping_address->setPostalCode('95132');
    $shipping_address->setLine1('My St');
    $shipping_address->setState('CA');
    $shipping_address->setRecipientName('Recipient Name');

    $billing_address = new Address();
    $billing_address->setCity('San Jose');
    $billing_address->setCountryCode('US');
    $billing_address->setPostalCode('95132');
    $billing_address->setLine1('My St2');
    $billing_address->setState('CA');

    $payer_info = new PayerInfo();
    $payer_info->setBillingAddress($billing_address);
    $payer_info->setEmail('a@2.com');
    $payer->setPayerInfo($payer_info);

    $item_list = new ItemList();
    $item_list->setItems(array($item_1, $item_2));
    $item_list->setShippingAddress($shipping_address);

    $amount = new Amount();
    $amount->setCurrency('USD')
        ->setTotal(Input::get('amount') + 20);

    $transaction = new Transaction();
    $transaction->setAmount($amount)
        ->setItemList($item_list)
        ->setDescription('Your transaction description');

    $payee_email = Input::get('payee');
    if ($payee_email) {
        $payee = new Payee();
        $payee->setEmail($payee_email);
        $transaction->setPayee($payee);
    }

    $redirect_urls = new RedirectUrls();
    $redirect_urls->setReturnUrl(url('paypal/status')) /** Specify return URL **/
        ->setCancelUrl(url('paypal/status'));

    $payment = new Payment();
    $payment->setIntent('Sale')
        ->setPayer($payer)
        ->setRedirectUrls($redirect_urls)
        ->setTransactions(array($transaction));

    try {
        $payment->create(PaypalController::$_api_context);
    } catch (\PayPal\Exception\PPConnectionException $ex) {
        return json_decode($ex->getData());
        return 'Error: ' . $ex->getMessage();
    }

    foreach ($payment->getLinks() as $link) {
        if ($link->getRel() == 'approval_url') {
            $redirect_url = $link->getHref();
                break;
        }
    }

    /** add payment ID to session **/
    Session::put('paypal_payment_id', $payment->getId());
    if (isset($redirect_url)) {
    /** redirect to paypal **/
        return Redirect::away($redirect_url);
    }

    return 'Unknown error occurred';

It is from PayPal sample code almost same as this link - http://paypal.github.io/PayPal-PHP-SDK/sample/doc/payments/CreatePaymentUsingPayPal.html

How can I do this.

Thanks much to anyone help.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
    • ¥500 火焰左右视图、视差(基于双目相机)