diff --git a/.gitignore b/.gitignore index 3de14bd7..b360b7b9 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,4 @@ releaseguide.md venv/ .idea/ .coverage -.vagrant/ \ No newline at end of file +.vagrant/ diff --git a/Adyen/client.py b/Adyen/client.py index f8c5e289..0dbc955c 100644 --- a/Adyen/client.py +++ b/Adyen/client.py @@ -407,8 +407,13 @@ def call_checkout_api(self, request_data, endpoint, idempotency_key=None, errorstring = "'platform' must be the value of 'live' or 'test'" raise ValueError(errorstring) - if not request_data.get('merchantAccount'): - request_data['merchantAccount'] = self.merchant_account + merchant_account_not_required = [ + 'applePay/sessions' + ] + + if request_data.get('merchantAccount') is None: + if endpoint not in merchant_account_not_required: + request_data['merchantAccount'] = self.merchant_account with_app_info = [ "authorise", diff --git a/Adyen/services/checkout.py b/Adyen/services/checkout.py index ffed9497..55386f00 100644 --- a/Adyen/services/checkout.py +++ b/Adyen/services/checkout.py @@ -118,3 +118,8 @@ def orders(self, request, **kwargs): def orders_cancel(self, request, **kwargs): endpoint = "orders/cancel" return self.client.call_checkout_api(request, endpoint, **kwargs) + + # Apple Pay session validation + def applepay_session(self, request, **kwargs): + endpoint = "applePay/sessions" + return self.client.call_checkout_api(request,endpoint,**kwargs) diff --git a/Vagrantfile b/Vagrantfile index 7a1a7576..2ee30bfa 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,20 +1,7 @@ -$script = <<-SCRIPT -sudo yum install -y https://repo.ius.io/ius-release-el7.rpm -echo "Run update" -sudo yum update -echo "Install python 3.6" -sudo yum install -y python36u python36u-libs python36u-devel python36u-pip -sudo yum install python2-pycodestyle -SCRIPT - Vagrant.configure("2") do |config| - config.vm.box = "centos/7" + config.vm.box = "jeffnoxon/ubuntu-20.04-arm64" config.vm.synced_folder '.', '/home/vagrant/adyen-python-api-library', disabled: false config.vm.synced_folder '.', '/vagrant', disabled: true config.vm.network :forwarded_port, guest:3001, host: 3001 - config.vm.provider :virtualbox do |vb| - vb.name = "adyen-python-api-library" - vb.customize ["modifyvm", :id, "--memory", "1024", "--cpus", "2"] - end - config.vm.provision "shell", inline: $script + config.vm.provider :parallels end \ No newline at end of file diff --git a/test/CheckoutUtilityTest.py b/test/CheckoutUtilityTest.py index 8682ca33..5182e8b2 100644 --- a/test/CheckoutUtilityTest.py +++ b/test/CheckoutUtilityTest.py @@ -54,3 +54,16 @@ def test_checkout_utility_api_url_custom(self): url = self.ady.client._determine_checkout_url("test", "originKeys") self.assertEqual(url, "https://checkout-test.adyen.com/v1/originKeys") + + def test_applePay_session(self): + request = { + "displayName": "YOUR_MERCHANT_NAME", + "domainName": "YOUR_DOMAIN_NAME", + "merchantIdentifier": "YOUR_MERCHANT_ID" + } + self.ady.client = self.test.create_client_from_file(200, request, "test/mocks/" + "checkoututility/" + "applepay-sessions" + "-success.json") + result = self.ady.checkout.applepay_session(request) + self.assertEqual("BASE_64_ENCODED_DATA", result.message['data']) diff --git a/test/mocks/checkoututility/applepay-sessions-success.json b/test/mocks/checkoututility/applepay-sessions-success.json new file mode 100644 index 00000000..3492cd4a --- /dev/null +++ b/test/mocks/checkoututility/applepay-sessions-success.json @@ -0,0 +1,3 @@ +{ + "data": "BASE_64_ENCODED_DATA" +}