public void PaymentNullAccessToken() { var payment = GetPaymentForSale(); string accessToken = null; TestingUtil.AssertThrownException <System.ArgumentNullException>(() => payment.Create(new APIContext(accessToken))); }
public void PlanDeleteTest() { try { var plan = GetPlan(); var createdPlan = plan.Create(TestingUtil.GetApiContext()); var planId = createdPlan.id; // Create a patch request that will delete the plan var patchRequest = new PatchRequest { new Patch { op = "replace", path = "/", value = new Plan { state = "DELETED" } } }; createdPlan.Update(TestingUtil.GetApiContext(), patchRequest); // Attempting to retrieve the plan should result in a PayPalException being thrown. TestingUtil.AssertThrownException <PaymentsException>(() => Plan.Get(TestingUtil.GetApiContext(), planId)); } finally { TestingUtil.RecordConnectionDetails(); } }
public void WebhookEventValidateReceivedEventInvalidApiContextTest() { var requestBody = "{\"id\":\"WH-2W7266712B616591M-36507203HX6402335\",\"create_time\":\"2019-05-28T01:28:46Z\",\"resource_type\":\"sale\",\"event_type\":\"PAYMENT.SALE.COMPLETED\",\"summary\":\"Payment completed for $ 20.0 USD\",\"resource\":{\"id\":\"7DW85331GX749735N\",\"create_time\":\"2015-05-12T18:13:18Z\",\"update_time\":\"2015-05-12T18:13:36Z\",\"amount\":{\"total\":\"20.00\",\"currency\":\"USD\"},\"payment_mode\":\"INSTANT_TRANSFER\",\"state\":\"completed\",\"protection_eligibility\":\"ELIGIBLE\",\"protection_eligibility_type\":\"ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE\",\"parent_payment\":\"PAY-1A142943SV880364LKVJEFPQ\",\"transaction_fee\":{\"value\":\"0.88\",\"currency\":\"USD\"},\"links\":[{\"href\":\"https://api.sandbox.paypal.com/v1/payments/sale/7DW85331GX749735N\",\"rel\":\"self\",\"method\":\"GET\"},{\"href\":\"https://api.sandbox.paypal.com/v1/payments/sale/7DW85331GX749735N/refund\",\"rel\":\"refund\",\"method\":\"POST\"},{\"href\":\"https://api.sandbox.paypal.com/v1/payments/payment/PAY-1A142943SV880364LKVJEFPQ\",\"rel\":\"parent_payment\",\"method\":\"GET\"}]},\"links\":[{\"href\":\"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-2W7266712B616591M-36507203HX6402335\",\"rel\":\"self\",\"method\":\"GET\"},{\"href\":\"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-2W7266712B616591M-36507203HX6402335/resend\",\"rel\":\"resend\",\"method\":\"POST\"}]}"; var requestHeaders = new NameValueCollection { { "Paypal-Cert-Url", "https://api.sandbox.paypal.com/v1/notifications/certs/CERT-360caa42-fca2a594-1d93a270" }, { "Paypal-Auth-Version", "v2" }, { "Paypal-Transmission-Sig", "vSOIQFIZQHv8G2vpbOpD/4fSC4/MYhdHyv+AmgJyeJQq6q5avWyHIe/zL6qO5hle192HSqKbYveLoFXGJun2od2zXN3Q45VBXwdX3woXYGaNq532flAtiYin+tQ/0pNwRDsVIufCxa3a8HskaXy+YEfXNnwCSL287esD3HgOHmuAs0mYKQdbR4e8Evk8XOOQaZzGeV7GNXXz19gzzvyHbsbHmDz5VoRl9so5OoHqvnc5RtgjZfG8KA9lXh2MTPSbtdTLQb9ikKYnOGM+FasFMxk5stJisgmxaefpO9Q1qm3rCjaJ29aAOyDNr3Q7WkeN3w4bSXtFMwyRBOF28pJg9g==" }, { "Paypal-Transmission-Id", "f0192050-80e7-11e9-a416-b554c1da3649" }, { "Paypal-Auth-Algo", "SHA256withRSA" }, { "Paypal-Transmission-Time", "2019-05-28T01:28:46Z" } }; var verification = new VerifyWebhookSignature() { auth_algo = requestHeaders["Paypal-Auth-Algo"], cert_url = requestHeaders["Paypal-Cert-Url"], transmission_id = requestHeaders["Paypal-Transmission-Id"], transmission_sig = requestHeaders["Paypal-Transmission-Sig"], transmission_time = requestHeaders["Paypal-Transmission-Time"], webhook_event = JsonFormatter.ConvertFromJson <WebhookEvent>(requestBody) }; TestingUtil.AssertThrownException <ArgumentNullException>(() => verification.Post(null)); }
public void WebhookEventValidateNotSupportedAuthAlgorithm() { TestingUtil.AssertThrownException <AlgorithmNotSupportedException>(() => WebhookEvent.ConvertAuthAlgorithmHeaderToHashAlgorithmName("SHA1withDSA")); TestingUtil.AssertThrownException <AlgorithmNotSupportedException>(() => WebhookEvent.ConvertAuthAlgorithmHeaderToHashAlgorithmName("SHA256withDSA")); TestingUtil.AssertThrownException <AlgorithmNotSupportedException>(() => WebhookEvent.ConvertAuthAlgorithmHeaderToHashAlgorithmName("SHA512withDSA")); TestingUtil.AssertThrownException <AlgorithmNotSupportedException>(() => WebhookEvent.ConvertAuthAlgorithmHeaderToHashAlgorithmName("MD5withDSA")); }
public void APIContextInvalidAccessTokenConstructorTest() { TestingUtil.AssertThrownException <System.ArgumentNullException>(() => new APIContext("")); TestingUtil.AssertThrownException <System.ArgumentNullException>(() => new APIContext("", "xyz")); TestingUtil.AssertThrownException <System.ArgumentNullException>(() => new APIContext(null)); TestingUtil.AssertThrownException <System.ArgumentNullException>(() => new APIContext(null, "xyz")); }
public void WebProfileDeleteTest() { try { // Create a new profile var profileName = Guid.NewGuid().ToString(); var profile = WebProfileTest.GetWebProfile(); profile.name = profileName; var createdProfile = profile.Create(TestingUtil.GetApiContext()); // Get the profile object for the new profile profile = WebProfile.Get(TestingUtil.GetApiContext(), createdProfile.id); // Delete the profile profile.Delete(TestingUtil.GetApiContext()); // Attempt to get the profile. This should result in an exception. TestingUtil.AssertThrownException <PayPal.HttpException>(() => { WebProfile.Get(TestingUtil.GetApiContext(), profile.id); }); } catch (ConnectionException ex) { TestingUtil.WriteConnectionExceptionDetails(ex); throw; } }
public void OAuthTokenCredentialMissingClientSecretTest() { var config = ConfigManager.Instance.GetProperties(); config[BaseConstants.ClientSecret] = ""; var oauthTokenCredential = new OAuthTokenCredential(config); TestingUtil.AssertThrownException <MissingCredentialException>(() => oauthTokenCredential.GetAccessToken()); }
public void AuthroizationReauthorizeTest() { var authorization = Authorization.Get(TestingUtil.GetApiContext(), "7GH53639GA425732B"); var reauthorizeAmount = new Amount(); reauthorizeAmount.currency = "USD"; reauthorizeAmount.total = "1"; authorization.amount = reauthorizeAmount; TestingUtil.AssertThrownException <PayPal.PaymentsException>(() => authorization.Reauthorize(TestingUtil.GetApiContext())); }
public void WebhookDeleteTest() { var webhook = WebhookTest.GetWebhook(); webhook.url = "https://" + Guid.NewGuid().ToString() + ".com/paypal_webhooks"; var createdWebhook = webhook.Create(TestingUtil.GetApiContext()); createdWebhook.Delete(TestingUtil.GetApiContext()); TestingUtil.AssertThrownException <HttpException>(() => Webhook.Get(TestingUtil.GetApiContext(), createdWebhook.id)); }
public void WebhookDeleteTest() { try { var webhook = WebhookTest.GetWebhook(); webhook.url = "https://" + Guid.NewGuid().ToString() + ".com/paypal_webhooks"; var createdWebhook = webhook.Create(TestingUtil.GetApiContext()); createdWebhook.Delete(TestingUtil.GetApiContext()); TestingUtil.AssertThrownException <HttpException>(() => Webhook.Get(TestingUtil.GetApiContext(), createdWebhook.id)); } catch (ConnectionException ex) { TestingUtil.WriteConnectionExceptionDetails(ex); throw; } }
public void WebhookEventValidateReceivedEventMissingWebhookIdTest() { var requestBody = "{\"id\":\"WH-2W7266712B616591M-36507203HX6402335\",\"create_time\":\"2015-05-12T18:14:14Z\",\"resource_type\":\"sale\",\"event_type\":\"PAYMENT.SALE.COMPLETED\",\"summary\":\"Payment completed for $ 20.0 USD\",\"resource\":{\"id\":\"7DW85331GX749735N\",\"create_time\":\"2015-05-12T18:13:18Z\",\"update_time\":\"2015-05-12T18:13:36Z\",\"amount\":{\"total\":\"20.00\",\"currency\":\"USD\"},\"payment_mode\":\"INSTANT_TRANSFER\",\"state\":\"completed\",\"protection_eligibility\":\"ELIGIBLE\",\"protection_eligibility_type\":\"ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE\",\"parent_payment\":\"PAY-1A142943SV880364LKVJEFPQ\",\"transaction_fee\":{\"value\":\"0.88\",\"currency\":\"USD\"},\"links\":[{\"href\":\"https://api.sandbox.paypal.com/v1/payments/sale/7DW85331GX749735N\",\"rel\":\"self\",\"method\":\"GET\"},{\"href\":\"https://api.sandbox.paypal.com/v1/payments/sale/7DW85331GX749735N/refund\",\"rel\":\"refund\",\"method\":\"POST\"},{\"href\":\"https://api.sandbox.paypal.com/v1/payments/payment/PAY-1A142943SV880364LKVJEFPQ\",\"rel\":\"parent_payment\",\"method\":\"GET\"}]},\"links\":[{\"href\":\"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-2W7266712B616591M-36507203HX6402335\",\"rel\":\"self\",\"method\":\"GET\"},{\"href\":\"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-2W7266712B616591M-36507203HX6402335/resend\",\"rel\":\"resend\",\"method\":\"POST\"}]}"; var requestHeaders = new NameValueCollection { { "Paypal-Cert-Url", "https://api.sandbox.paypal.com/v1/notifications/certs/CERT-360caa42-fca2a594-a5cafa77" }, { "Paypal-Auth-Version", "v2" }, { "Paypal-Transmission-Sig", "vSOIQFIZQHv8G2vpbOpD/4fSC4/MYhdHyv+AmgJyeJQq6q5avWyHIe/zL6qO5hle192HSqKbYveLoFXGJun2od2zXN3Q45VBXwdX3woXYGaNq532flAtiYin+tQ/0pNwRDsVIufCxa3a8HskaXy+YEfXNnwCSL287esD3HgOHmuAs0mYKQdbR4e8Evk8XOOQaZzGeV7GNXXz19gzzvyHbsbHmDz5VoRl9so5OoHqvnc5RtgjZfG8KA9lXh2MTPSbtdTLQb9ikKYnOGM+FasFMxk5stJisgmxaefpO9Q1qm3rCjaJ29aAOyDNr3Q7WkeN3w4bSXtFMwyRBOF28pJg9g==" }, { "Paypal-Transmission-Id", "b2384410-f8d2-11e4-8bf3-77339302725b" }, { "Paypal-Auth-Algo", "SHA256withRSA" }, { "Paypal-Transmission-Time", "2015-05-12T18:14:14Z" } }; var apiContext = TestingUtil.GetApiContext(); TestingUtil.AssertThrownException <PayPalException>(() => WebhookEvent.ValidateReceivedEvent(apiContext, requestHeaders, requestBody)); }
public void OAuthTokenCredentialInvalidClientSecretTest() { try { var config = ConfigManager.Instance.GetProperties(); config[BaseConstants.ClientSecret] = "abc"; var oauthTokenCredential = new OAuthTokenCredential(config); TestingUtil.AssertThrownException <IdentityException>(() => oauthTokenCredential.GetAccessToken()); this.RecordConnectionDetails(); } catch (ConnectionException) { this.RecordConnectionDetails(false); throw; } }
public void CaptureNullIdTest() { TestingUtil.AssertThrownException <System.ArgumentNullException>(() => Capture.Get(new APIContext("token"), null)); }
public void AuthorizationNullIdTest() { TestingUtil.AssertThrownException <System.ArgumentNullException>(() => Authorization.Get(new APIContext("token"), null)); }
public void APIContextInvalidRequestIdConstructorTest() { TestingUtil.AssertThrownException <System.ArgumentNullException>(() => new APIContext("abc", "")); TestingUtil.AssertThrownException <System.ArgumentNullException>(() => new APIContext("abc", null)); }