Laravel Paypal - 通过网站传递送货地址
Laravel Paypal - pass shipping address from website
我刚刚从 net-shell (https://github.com/net-shell/laravel-paypal) 为 Laravel 实施了 PayPal API,目前为止一切正常,但现在有一件事我' m 丢失或我不知道该怎么做:在我的门户中,用户必须使用他们的地址进行注册。我想要的是这封电子邮件(用于在我的门户网站上注册)用作送货地址,稍后也会在 PayPal 网站上显示(因此无论用户为 PayPal 输入什么地址)。
有什么办法吗?
我知道好像有一个PayPal:ShippingAdress,我可以用,但是如果这个是对的,那我怎么分配给付款呢?
Edit:我现在尝试了很多变体,比如 $transaction->setShippingAddress();
或 $payer->setShippingAddress();
或 $payment->setShippingAddress();
但没有任何效果,方法是从未发现。现在在 Paypal/Api/ShippingAddress 中我找到了 setDefaultAddress 方法,所以我想创建这样一个对象并像这样使用这个方法:
$shippingAddress = [
"recipient_name" => "John Johnson",
"line1" => "Whatever street 2",
"line2" => "Another street 2",
"city" => "London",
"country_code" => "UK",
"postal_code" => "NR30 1LY",
"state" => "England",
"phone" => "3123123123"
];
$shippingAddr = PayPal::ShippingAddresss();
$shippingAddr->setDefaultAddress($shippingAddress);
使用此代码不会出现错误,但它也没有设置地址,我现在需要将这个创建的 shippingAddress 对象分配给付款或交易,就像我使用详细信息一样,创建详细信息对象然后使用$amount->setDetails($details);
,但我没有找到任何关于 shippingAddress 的信息.....
编辑2:
通过项目列表获得提示,这就是我创建和设置该列表的方式:
$itemList = PayPal::itemList();
foreach ($items as $item)
$product = Product::where('id', '=', $item->product->id)->first();
$itemName = $product->name;
$itemPrice = $product->price;
$itemAmount = $item->amount;
$payPalItem = PayPal::item();
$payPalItem->setName($itemName)
->setDescription($itemName)
->setCurrency('EUR')
->setQuantity($itemAmount)
->setPrice($itemPrice);
$itemList->addItem($payPalItem);
}
然后
$transaction = PayPal::Transaction();
$transaction->setAmount($amount);
$transaction->setItemList($itemList);
在paypal中创建一个IPN,检查session属性是否传递正确。如果用户使用不同的电子邮件,则交易无效。
在chat-research完成问题作者(@nameless - 问候!)后,我们发现添加另一个收货地址的地方是itemList:
您根据订单收集物品
$itemList = PayPal::itemList();
foreach ($items as $item)
$product = Product::where('id', '=', $item->product->id)->first();
$itemName = $product->name;
$itemPrice = $product->price;
$itemAmount = $item->amount;
$payPalItem = PayPal::item();
$payPalItem->setName($itemName)
->setDescription($itemName)
->setCurrency('EUR')
->setQuantity($itemAmount)
->setPrice($itemPrice);
$itemList->addItem($payPalItem);
}
最后一步是将地址附加到 $itemList
$shippingAddress = [
"recipient_name" => "John Johnson",
"line1" => "Whatever street 2",
"line2" => "Another street 2",
"city" => "London",
"country_code" => "GB",
"postal_code" => "NR30 1LY",
"state" => "England",
"phone" => "3123123123"
];
$itemList->setShippingAddress($shippingAddres);
请注意,国家/地区在 ISO 3166-1 中,因此 GB - 不是英国。如果您输入错误的两个字母代码 - 响应将 return 400 代码格式错误。
我刚刚从 net-shell (https://github.com/net-shell/laravel-paypal) 为 Laravel 实施了 PayPal API,目前为止一切正常,但现在有一件事我' m 丢失或我不知道该怎么做:在我的门户中,用户必须使用他们的地址进行注册。我想要的是这封电子邮件(用于在我的门户网站上注册)用作送货地址,稍后也会在 PayPal 网站上显示(因此无论用户为 PayPal 输入什么地址)。
有什么办法吗?
我知道好像有一个PayPal:ShippingAdress,我可以用,但是如果这个是对的,那我怎么分配给付款呢?
Edit:我现在尝试了很多变体,比如 $transaction->setShippingAddress();
或 $payer->setShippingAddress();
或 $payment->setShippingAddress();
但没有任何效果,方法是从未发现。现在在 Paypal/Api/ShippingAddress 中我找到了 setDefaultAddress 方法,所以我想创建这样一个对象并像这样使用这个方法:
$shippingAddress = [
"recipient_name" => "John Johnson",
"line1" => "Whatever street 2",
"line2" => "Another street 2",
"city" => "London",
"country_code" => "UK",
"postal_code" => "NR30 1LY",
"state" => "England",
"phone" => "3123123123"
];
$shippingAddr = PayPal::ShippingAddresss();
$shippingAddr->setDefaultAddress($shippingAddress);
使用此代码不会出现错误,但它也没有设置地址,我现在需要将这个创建的 shippingAddress 对象分配给付款或交易,就像我使用详细信息一样,创建详细信息对象然后使用$amount->setDetails($details);
,但我没有找到任何关于 shippingAddress 的信息.....
编辑2: 通过项目列表获得提示,这就是我创建和设置该列表的方式:
$itemList = PayPal::itemList();
foreach ($items as $item)
$product = Product::where('id', '=', $item->product->id)->first();
$itemName = $product->name;
$itemPrice = $product->price;
$itemAmount = $item->amount;
$payPalItem = PayPal::item();
$payPalItem->setName($itemName)
->setDescription($itemName)
->setCurrency('EUR')
->setQuantity($itemAmount)
->setPrice($itemPrice);
$itemList->addItem($payPalItem);
}
然后
$transaction = PayPal::Transaction();
$transaction->setAmount($amount);
$transaction->setItemList($itemList);
在paypal中创建一个IPN,检查session属性是否传递正确。如果用户使用不同的电子邮件,则交易无效。
在chat-research完成问题作者(@nameless - 问候!)后,我们发现添加另一个收货地址的地方是itemList:
您根据订单收集物品
$itemList = PayPal::itemList();
foreach ($items as $item)
$product = Product::where('id', '=', $item->product->id)->first();
$itemName = $product->name;
$itemPrice = $product->price;
$itemAmount = $item->amount;
$payPalItem = PayPal::item();
$payPalItem->setName($itemName)
->setDescription($itemName)
->setCurrency('EUR')
->setQuantity($itemAmount)
->setPrice($itemPrice);
$itemList->addItem($payPalItem);
}
最后一步是将地址附加到 $itemList
$shippingAddress = [
"recipient_name" => "John Johnson",
"line1" => "Whatever street 2",
"line2" => "Another street 2",
"city" => "London",
"country_code" => "GB",
"postal_code" => "NR30 1LY",
"state" => "England",
"phone" => "3123123123"
];
$itemList->setShippingAddress($shippingAddres);
请注意,国家/地区在 ISO 3166-1 中,因此 GB - 不是英国。如果您输入错误的两个字母代码 - 响应将 return 400 代码格式错误。