Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shipping preference option to RestPurchaseRequest #184

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/Message/RestPurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,41 @@
*/
class RestPurchaseRequest extends RestAuthorizeRequest
{
const SHIPPING_PREFERENCE_NO_SHIPPING = 'NO_SHIPPING';
const SHIPPING_PREFERENCE_GET_FROM_FILE = 'GET_FROM_FILE';
const SHIPPING_PREFERENCE_SET_PROVIDED_ADDRESS= 'SET_PROVIDED_ADDRESS';

public function getData()
{
$data = parent::getData();
$data['intent'] = 'sale';
$data['application_context']['shipping_preference'] = $this->getShippingPreference();
return $data;
}

public function getShippingPreference()
{
return $this->getParameter('shippingPreference');
}

/**
* Set the shipping preference
*
* Supported values:
* 'NO_SHIPPING': redacts shipping address fields from the PayPal pages.
* Recommended value to use for digital goods.
* 'GET_FROM_FILE': Get the shipping address selected by the buyer on PayPal pages.
* 'SET_PROVIDED_ADDRESS' (not yet fully supported by the library since shipping address can't be provided):
* Use the address provided by the merchant. Buyer is not able to change the address on the PayPal pages.
* If merchant doesn't pass an address, buyer has the option to choose the address on PayPal pages.
*
* @param string $value
* @return bool.
* @link https://developer.paypal.com/docs/api/orders/#definition-application_context
* @link https://www.paypalobjects.com/api/checkout.js
*/
public function setShippingPreference($value)
{
return $this->setParameter('shippingPreference', $value);
}
}