Exemplo n.º 1
0
        public void AgreementUpdateTest()
        {
            try
            {
                // Get the agreement to be used for verifying the update functionality
                var apiContext  = TestingUtil.GetApiContext();
                var agreementId = "I-HP4H4YJFCN07";
                var agreement   = Agreement.Get(apiContext, agreementId);

                // Create an update for the agreement
                var updatedDescription = Guid.NewGuid().ToString();
                var patch = new Patch();
                patch.op    = "replace";
                patch.path  = "/";
                patch.value = new Agreement()
                {
                    description = updatedDescription
                };
                var patchRequest = new PatchRequest();
                patchRequest.Add(patch);

                // Update the agreement
                agreement.Update(apiContext, patchRequest);

                // Verify the agreement was successfully updated
                var updatedAgreement = Agreement.Get(apiContext, agreementId);
                Assert.AreEqual(agreementId, updatedAgreement.id);
                Assert.AreEqual(updatedDescription, updatedAgreement.description);
            }
            catch (ConnectionException ex)
            {
                TestingUtil.WriteConnectionExceptionDetails(ex);
                throw;
            }
        }
Exemplo n.º 2
0
        public void PaymentVerifyCreateCreditCardPaymentForSaleResponse()
        {
            try
            {
                var deserializationErrors = new List <string>();
                JsonFormatter.DeserializationError += (e) => { deserializationErrors.Add(e.Message); };

                var payment        = GetPaymentUsingCreditCard("sale");
                var createdPayment = payment.Create(TestingUtil.GetApiContext());

                // Verify no errors were encountered while deserializing the response.
                if (deserializationErrors.Any())
                {
                    Assert.Fail("Encountered errors while attempting to deserialize:" + Environment.NewLine + string.Join(Environment.NewLine, deserializationErrors));
                }

                // Verify the state of the response.
                Assert.AreEqual("approved", createdPayment.state);
                Assert.IsTrue(createdPayment.id.StartsWith("PAY-"));
                Assert.IsTrue(string.IsNullOrEmpty(createdPayment.token));

                // Verify the expected HATEOAS links: self
                Assert.AreEqual(1, createdPayment.links.Count);
                Assert.IsNotNull(createdPayment.GetHateoasLink(BaseConstants.HateoasLinkRelations.Self));
            }
            catch (ConnectionException ex)
            {
                TestingUtil.WriteConnectionExceptionDetails(ex);
                throw;
            }
        }
Exemplo n.º 3
0
        public void WebProfileCreateAndGetTest()
        {
            try
            {
                // Create the profile
                var apiContext = TestingUtil.GetApiContext();
                var profile    = WebProfileTest.GetWebProfile();
                profile.name = Guid.NewGuid().ToString();
                var response = profile.Create(apiContext);
                Assert.IsNotNull(response);
                Assert.IsNotNull(response.id);

                // Get the profile
                var profileId        = response.id;
                var retrievedProfile = WebProfile.Get(apiContext, profileId);
                Assert.AreEqual(profileId, retrievedProfile.id);

                // Delete the profile
                retrievedProfile.Delete(apiContext);
            }
            catch (ConnectionException ex)
            {
                TestingUtil.WriteConnectionExceptionDetails(ex);
                throw;
            }
        }
Exemplo n.º 4
0
        public void WebProfileUpdateTest()
        {
            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);

                // Update the profile
                var newName = "New " + profileName;
                profile.name = newName;
                profile.Update(TestingUtil.GetApiContext());

                // Get the profile again and verify it was successfully updated.
                var retrievedProfile = WebProfile.Get(TestingUtil.GetApiContext(), profile.id);
                Assert.AreEqual(newName, retrievedProfile.name);

                // Delete the profile
                profile.Delete(TestingUtil.GetApiContext());
            }
            catch (ConnectionException ex)
            {
                TestingUtil.WriteConnectionExceptionDetails(ex);
                throw;
            }
        }
Exemplo n.º 5
0
        public void WebhookCreateAndGetTest()
        {
            try
            {
                var apiContext = TestingUtil.GetApiContext();
                var webhook    = WebhookTest.GetWebhook();
                var url        = "https://" + Guid.NewGuid().ToString() + ".com/paypal_webhooks";
                webhook.url = url;
                var createdWebhook = webhook.Create(apiContext);
                Assert.IsNotNull(createdWebhook);
                Assert.IsTrue(!string.IsNullOrEmpty(createdWebhook.id));

                var webhookId        = createdWebhook.id;
                var retrievedWebhook = Webhook.Get(apiContext, webhookId);
                Assert.IsNotNull(retrievedWebhook);
                Assert.AreEqual(webhookId, retrievedWebhook.id);
                Assert.AreEqual(url, retrievedWebhook.url);

                // Cleanup
                retrievedWebhook.Delete(apiContext);
            }
            catch (ConnectionException ex)
            {
                TestingUtil.WriteConnectionExceptionDetails(ex);
                throw;
            }
        }
Exemplo n.º 6
0
        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));
            }
            catch (ConnectionException ex)
            {
                TestingUtil.WriteConnectionExceptionDetails(ex);
                throw;
            }
        }
Exemplo n.º 7
0
        public void SaleRefundTest()
        {
            try
            {
                // Create a credit card sale payment
                var payment = PaymentTest.CreatePaymentForSale();

                // Get the sale resource
                var sale = payment.transactions[0].related_resources[0].sale;

                var refund = new Refund
                {
                    amount = new Amount
                    {
                        currency = "USD",
                        total    = "0.01"
                    }
                };

                var response = sale.Refund(TestingUtil.GetApiContext(), refund);
                Assert.IsNotNull(response);
                Assert.AreEqual("completed", response.state);
            }
            catch (ConnectionException ex)
            {
                TestingUtil.WriteConnectionExceptionDetails(ex);
                throw;
            }
        }
Exemplo n.º 8
0
        public void PayoutItemDetailsCancelTest()
        {
            try
            {
                // Create a single synchronous payout with an invalid email address.
                // This will cause the status to be marked as 'UNCLAIMED', allowing
                // us to cancel the payout.
                var payoutBatch = PayoutTest.CreateSingleSynchronousPayoutBatch();

                Assert.IsNotNull(payoutBatch);
                Assert.IsNotNull(payoutBatch.items);
                Assert.IsTrue(payoutBatch.items.Count > 0);

                var payoutItem = payoutBatch.items[0];

                if (payoutItem.transaction_status == PayoutTransactionStatus.UNCLAIMED)
                {
                    var payoutItemDetails = PayoutItem.Cancel(TestingUtil.GetApiContext(), payoutItem.payout_item_id);

                    Assert.IsNotNull(payoutItemDetails);
                    Assert.AreEqual(PayoutTransactionStatus.RETURNED, payoutItemDetails.transaction_status);
                }
            }
            catch (ConnectionException ex)
            {
                TestingUtil.WriteConnectionExceptionDetails(ex);
                throw;
            }
        }
Exemplo n.º 9
0
        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;
            }
        }
Exemplo n.º 10
0
 public void CaptureRefundTest()
 {
     try
     {
         var pay             = PaymentTest.CreatePaymentAuthorization();
         var authorizationId = pay.transactions[0].related_resources[0].authorization.id;
         var authorization   = Authorization.Get(TestingUtil.GetApiContext(), authorizationId);
         var cap             = new Capture();
         var amnt            = new Amount();
         amnt.total    = "1";
         amnt.currency = "USD";
         cap.amount    = amnt;
         var response     = authorization.Capture(TestingUtil.GetApiContext(), cap);
         var fund         = new Refund();
         var refundAmount = new Amount();
         refundAmount.total    = "1";
         refundAmount.currency = "USD";
         fund.amount           = refundAmount;
         var responseRefund = response.Refund(TestingUtil.GetApiContext(), fund);
         Assert.AreEqual("completed", responseRefund.state);
     }
     catch (ConnectionException ex)
     {
         TestingUtil.WriteConnectionExceptionDetails(ex);
         throw;
     }
 }
Exemplo n.º 11
0
 public void PaymentStateTest()
 {
     try
     {
         var actual = CreatePaymentForSale();
         Assert.AreEqual("approved", actual.state);
     }
     catch (ConnectionException ex)
     {
         TestingUtil.WriteConnectionExceptionDetails(ex);
         throw;
     }
 }
Exemplo n.º 12
0
        public void WebhookUpdateTest()
        {
            try
            {
                var webhook = WebhookTest.GetWebhook();
                webhook.url = "https://" + Guid.NewGuid().ToString() + ".com/paypal_webhooks";
                var createdWebhook = webhook.Create(TestingUtil.GetApiContext());

                var newUrl           = "https://update.com/paypal_webhooks/" + Guid.NewGuid().ToString();
                var newEventTypeName = "PAYMENT.SALE.REFUNDED";

                var patchRequest = new PatchRequest
                {
                    new Patch
                    {
                        op    = "replace",
                        path  = "/url",
                        value = newUrl
                    },
                    new Patch
                    {
                        op    = "replace",
                        path  = "/event_types",
                        value = new List <WebhookEventType>
                        {
                            new WebhookEventType
                            {
                                name = newEventTypeName
                            }
                        }
                    }
                };

                var updatedWebhook = createdWebhook.Update(TestingUtil.GetApiContext(), patchRequest);
                Assert.IsNotNull(updatedWebhook);
                Assert.AreEqual(createdWebhook.id, updatedWebhook.id);
                Assert.AreEqual(newUrl, updatedWebhook.url);
                Assert.IsNotNull(updatedWebhook.event_types);
                Assert.AreEqual(1, updatedWebhook.event_types.Count);
                Assert.AreEqual(newEventTypeName, updatedWebhook.event_types[0].name);

                // Cleanup
                updatedWebhook.Delete(TestingUtil.GetApiContext());
            }
            catch (ConnectionException ex)
            {
                TestingUtil.WriteConnectionExceptionDetails(ex);
                throw;
            }
        }
Exemplo n.º 13
0
 public void PaymentListHistoryTest()
 {
     try
     {
         var context        = TestingUtil.GetApiContext();
         var paymentHistory = Payment.List(context, count: 10);
         Assert.IsTrue(paymentHistory.count > 0 && paymentHistory.count <= 10);
     }
     catch (ConnectionException ex)
     {
         TestingUtil.WriteConnectionExceptionDetails(ex);
         throw;
     }
 }
Exemplo n.º 14
0
 public void OrderGetTest()
 {
     try
     {
         var orderId = "O-2HT09787H36911800";
         var order   = Order.Get(TestingUtil.GetApiContext(), orderId);
         Assert.AreEqual(orderId, order.id);
     }
     catch (ConnectionException ex)
     {
         TestingUtil.WriteConnectionExceptionDetails(ex);
         throw;
     }
 }
Exemplo n.º 15
0
 public void WebhookGetListTest()
 {
     try
     {
         var webhookList = Webhook.GetAll(TestingUtil.GetApiContext());
         Assert.IsNotNull(webhookList);
         Assert.IsNotNull(webhookList.webhooks);
     }
     catch (ConnectionException ex)
     {
         TestingUtil.WriteConnectionExceptionDetails(ex);
         throw;
     }
 }
Exemplo n.º 16
0
 public void SaleGetTest()
 {
     try
     {
         var saleId = "4V7971043K262623A";
         var sale   = Sale.Get(TestingUtil.GetApiContext(), saleId);
         Assert.IsNotNull(sale);
         Assert.AreEqual(saleId, sale.id);
     }
     catch (ConnectionException ex)
     {
         TestingUtil.WriteConnectionExceptionDetails(ex);
         throw;
     }
 }
Exemplo n.º 17
0
 public void CreditCardListTest()
 {
     try
     {
         var creditCardList = CreditCard.List(TestingUtil.GetApiContext(), startTime: "2014-11-01T19:27:56Z", endTime: "2014-12-25T19:27:56Z");
         Assert.IsNotNull(creditCardList);
         Assert.IsTrue(creditCardList.total_items > 0);
         Assert.IsTrue(creditCardList.total_pages > 0);
     }
     catch (ConnectionException ex)
     {
         TestingUtil.WriteConnectionExceptionDetails(ex);
         throw;
     }
 }
Exemplo n.º 18
0
 public void CreditCardDeleteTest()
 {
     try
     {
         var card = GetCreditCard();
         var createdCreditCard   = card.Create(TestingUtil.GetApiContext());
         var retrievedCreditCard = CreditCard.Get(TestingUtil.GetApiContext(), createdCreditCard.id);
         retrievedCreditCard.Delete(TestingUtil.GetApiContext());
     }
     catch (ConnectionException ex)
     {
         TestingUtil.WriteConnectionExceptionDetails(ex);
         throw;
     }
 }
Exemplo n.º 19
0
 public void AuthorizationGetTest()
 {
     try
     {
         var pay             = PaymentTest.CreatePaymentAuthorization();
         var authorizationId = pay.transactions[0].related_resources[0].authorization.id;
         var authorize       = Authorization.Get(TestingUtil.GetApiContext(), authorizationId);
         Assert.AreEqual(authorizationId, authorize.id);
     }
     catch (ConnectionException ex)
     {
         TestingUtil.WriteConnectionExceptionDetails(ex);
         throw;
     }
 }
Exemplo n.º 20
0
 public void PlanListTest()
 {
     try
     {
         var planList = Plan.List(TestingUtil.GetApiContext());
         Assert.IsNotNull(planList);
         Assert.IsNotNull(planList.plans);
         Assert.IsTrue(planList.plans.Count > 0);
     }
     catch (ConnectionException ex)
     {
         TestingUtil.WriteConnectionExceptionDetails(ex);
         throw;
     }
 }
Exemplo n.º 21
0
 public void FuturePaymentTest()
 {
     try
     {
         var context          = TestingUtil.GetApiContext();
         var futurePayment    = CreateFuturePayment();
         var retrievedPayment = FuturePayment.Get(context, futurePayment.id);
         Assert.AreEqual(futurePayment.id, retrievedPayment.id);
     }
     catch (ConnectionException ex)
     {
         TestingUtil.WriteConnectionExceptionDetails(ex);
         throw;
     }
 }
Exemplo n.º 22
0
 public void PaymentCreateAndGetTest()
 {
     try
     {
         var context          = TestingUtil.GetApiContext();
         var pay              = CreatePaymentForSale();
         var retrievedPayment = Payment.Get(context, pay.id);
         Assert.AreEqual(pay.id, retrievedPayment.id);
     }
     catch (ConnectionException ex)
     {
         TestingUtil.WriteConnectionExceptionDetails(ex);
         throw;
     }
 }
Exemplo n.º 23
0
 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;
     }
 }
Exemplo n.º 24
0
 public void PayoutItemGetTest()
 {
     try
     {
         var payoutItemId      = "G2CFT8SJRB7RN";
         var payoutItemDetails = PayoutItem.Get(TestingUtil.GetApiContext(), payoutItemId);
         Assert.IsNotNull(payoutItemDetails);
         Assert.AreEqual(payoutItemId, payoutItemDetails.payout_item_id);
         Assert.AreEqual("8NX77PFLN255E", payoutItemDetails.payout_batch_id);
     }
     catch (ConnectionException ex)
     {
         TestingUtil.WriteConnectionExceptionDetails(ex);
         throw;
     }
 }
Exemplo n.º 25
0
 public void AgreementSearchTest()
 {
     try
     {
         var startDate    = "2014-10-01";
         var endDate      = "2014-10-14";
         var transactions = Agreement.ListTransactions(TestingUtil.GetApiContext(), "I-9STXMKR58UNN", startDate, endDate);
         Assert.IsNotNull(transactions);
         Assert.IsNotNull(transactions.agreement_transaction_list);
     }
     catch (ConnectionException ex)
     {
         TestingUtil.WriteConnectionExceptionDetails(ex);
         throw;
     }
 }
Exemplo n.º 26
0
 public void InvoiceCreateTest()
 {
     try
     {
         var invoice = GetInvoice();
         invoice.merchant_info.address.phone = null;
         invoice.shipping_info.address.phone = null;
         var createdInvoice = invoice.Create(TestingUtil.GetApiContext());
         Assert.IsNotNull(createdInvoice.id);
         Assert.AreEqual(invoice.note, createdInvoice.note);
     }
     catch (ConnectionException ex)
     {
         TestingUtil.WriteConnectionExceptionDetails(ex);
         throw;
     }
 }
Exemplo n.º 27
0
 public void InvoiceQrCodeTest()
 {
     try
     {
         var invoice        = GetInvoice();
         var createdInvoice = invoice.Create(TestingUtil.GetApiContext());
         var qrCode         = Invoice.QrCode(TestingUtil.GetApiContext(), createdInvoice.id);
         Assert.IsNotNull(qrCode);
         Assert.IsTrue(!string.IsNullOrEmpty(qrCode.image));
         createdInvoice.Delete(TestingUtil.GetApiContext());
     }
     catch (ConnectionException ex)
     {
         TestingUtil.WriteConnectionExceptionDetails(ex);
         throw;
     }
 }
Exemplo n.º 28
0
 public void AuthroizationReauthorizeTest()
 {
     try
     {
         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()));
     }
     catch (ConnectionException ex)
     {
         TestingUtil.WriteConnectionExceptionDetails(ex);
         throw;
     }
 }
Exemplo n.º 29
0
 public void AgreementExecuteTest()
 {
     try
     {
         var agreement = new Agreement()
         {
             token = "EC-2CD33889A9699491E"
         };
         var executedAgreement = agreement.Execute(TestingUtil.GetApiContext());
         Assert.AreEqual("I-ASXCM9U5MJJV", executedAgreement.id);
     }
     catch (ConnectionException ex)
     {
         TestingUtil.WriteConnectionExceptionDetails(ex);
         throw;
     }
 }
Exemplo n.º 30
0
        public void CreditCardUpdateTest()
        {
            try
            {
                var creditCard = CreateCreditCard();

                // Create a patch request to update the credit card.
                var patchRequest = new PatchRequest
                {
                    new Patch
                    {
                        op    = "replace",
                        path  = "/billing_address",
                        value = new Address
                        {
                            line1        = "111 First Street",
                            city         = "Saratoga",
                            country_code = "US",
                            state        = "CA",
                            postal_code  = "95070"
                        }
                    }
                };

                var apiContext        = TestingUtil.GetApiContext();
                var updatedCreditCard = creditCard.Update(apiContext, patchRequest);

                // Retrieve the credit card details from the vault and verify the
                // billing address was updated properly.
                var retrievedCreditCard = CreditCard.Get(apiContext, updatedCreditCard.id);
                Assert.IsNotNull(retrievedCreditCard);
                Assert.IsNotNull(retrievedCreditCard.billing_address);
                Assert.AreEqual("111 First Street", retrievedCreditCard.billing_address.line1);
                Assert.AreEqual("Saratoga", retrievedCreditCard.billing_address.city);
                Assert.AreEqual("US", retrievedCreditCard.billing_address.country_code);
                Assert.AreEqual("CA", retrievedCreditCard.billing_address.state);
                Assert.AreEqual("95070", retrievedCreditCard.billing_address.postal_code);
            }
            catch (ConnectionException ex)
            {
                TestingUtil.WriteConnectionExceptionDetails(ex);
                throw;
            }
        }