diff --git a/src/Message/AbstractRestRequest.php b/src/Message/AbstractRestRequest.php index 19ef31e..420ec01 100644 --- a/src/Message/AbstractRestRequest.php +++ b/src/Message/AbstractRestRequest.php @@ -31,6 +31,9 @@ abstract class AbstractRestRequest extends \Omnipay\Common\Message\AbstractRequest { const API_VERSION = 'v1'; + 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'; /** * Sandbox Endpoint URL @@ -202,4 +205,31 @@ protected function createResponse($data, $statusCode) { return $this->response = new RestResponse($this, $data, $statusCode); } + + 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); + } } diff --git a/src/Message/RestAuthorizeRequest.php b/src/Message/RestAuthorizeRequest.php index 8694df0..7f812c5 100644 --- a/src/Message/RestAuthorizeRequest.php +++ b/src/Message/RestAuthorizeRequest.php @@ -232,7 +232,8 @@ public function getData() ), ) ), - 'experience_profile_id' => $this->getExperienceProfileId() + 'experience_profile_id' => $this->getExperienceProfileId(), + 'application_context' => ['shipping_preference' => parent::getShippingPreference()], ); $items = $this->getItems(); diff --git a/src/Message/RestPurchaseRequest.php b/src/Message/RestPurchaseRequest.php index 6f12d29..60cb527 100644 --- a/src/Message/RestPurchaseRequest.php +++ b/src/Message/RestPurchaseRequest.php @@ -223,41 +223,12 @@ */ 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); + return $data; } } diff --git a/tests/Message/RestAuthorizeRequestTest.php b/tests/Message/RestAuthorizeRequestTest.php index 5f0f962..5ba62ae 100644 --- a/tests/Message/RestAuthorizeRequestTest.php +++ b/tests/Message/RestAuthorizeRequestTest.php @@ -126,4 +126,13 @@ public function testDescription() $this->request->setDescription('Sheep'); $this->assertEquals('abc123 : Sheep', $this->request->getDescription()); } + + public function testSetShippingPreference() + { + self::assertNull($this->request->getShippingPreference()); + + $this->request->setShippingPreference(AbstractRestRequest::SHIPPING_PREFERENCE_NO_SHIPPING); + + self::assertSame(AbstractRestRequest::SHIPPING_PREFERENCE_NO_SHIPPING, $this->request->getShippingPreference()); + } } diff --git a/tests/Message/RestCompletePurchaseRequestTest.php b/tests/Message/RestCompletePurchaseRequestTest.php index 4dfbf98..6d1d992 100644 --- a/tests/Message/RestCompletePurchaseRequestTest.php +++ b/tests/Message/RestCompletePurchaseRequestTest.php @@ -29,9 +29,8 @@ public function testGetData() { $this->request->setTransactionReference('abc123'); $this->request->setPayerId('Payer12345'); - $data = $this->request->getData(); $this->assertSame('Payer12345', $data['payer_id']); } -} \ No newline at end of file +}