예제 #1
0
 public void RefundIdTest()
 {
     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 amt             = new Amount();
         amt.total    = "1";
         amt.currency = "USD";
         cap.amount   = amt;
         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);
         var retrievedRefund = Refund.Get(TestingUtil.GetApiContext(), responseRefund.id);
         Assert.AreEqual(responseRefund.id, retrievedRefund.id);
     }
     catch (ConnectionException ex)
     {
         TestingUtil.WriteConnectionExceptionDetails(ex);
         throw;
     }
 }
        public void WebProfileUpdateTest()
        {
            // 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());
        }
        public void AgreementUpdateTest()
        {
            // 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);
        }
예제 #4
0
        public void PlanCreateAndGetTest()
        {
            try
            {
                var apiContext = TestingUtil.GetApiContext();
                this.RecordConnectionDetails();

                var plan        = GetPlan();
                var createdPlan = plan.Create(apiContext);
                this.RecordConnectionDetails();

                Assert.IsTrue(!string.IsNullOrEmpty(createdPlan.id));
                Assert.AreEqual(plan.name, createdPlan.name);

                var retrievedPlan = Plan.Get(apiContext, createdPlan.id);
                this.RecordConnectionDetails();

                Assert.IsNotNull(retrievedPlan);
                Assert.AreEqual(createdPlan.id, retrievedPlan.id);
                Assert.AreEqual("T-Shirt of the Month Club Plan", retrievedPlan.name);
                Assert.AreEqual("Template creation.", retrievedPlan.description);
                Assert.AreEqual("FIXED", retrievedPlan.type);
            }
            catch (ConnectionException)
            {
                this.RecordConnectionDetails(false);
                throw;
            }
        }
        public void WebProfileGetTest()
        {
            var profileId = "XP-5CQ3-3XSL-DDAA-MATK";
            var profile   = WebProfile.Get(TestingUtil.GetApiContext(), profileId);

            Assert.AreEqual(profileId, profile.id);
        }
예제 #6
0
        public void PaymentNullAccessToken()
        {
            var    payment     = GetPaymentForSale();
            string accessToken = null;

            TestingUtil.AssertThrownException <System.ArgumentNullException>(() => payment.Create(new APIContext(accessToken)));
        }
예제 #7
0
        public static Payment CreateFuturePayment()
        {
            FuturePayment pay = new FuturePayment();

            pay.intent = "sale";
            CreditCard card = CreditCardTest.GetCreditCard();
            List <FundingInstrument> fundingInstruments = new List <FundingInstrument>();
            FundingInstrument        fundingInstrument  = new FundingInstrument();

            fundingInstrument.credit_card = card;
            fundingInstruments.Add(fundingInstrument);
            Payer payer = new Payer();

            payer.payment_method      = "credit_card";
            payer.funding_instruments = fundingInstruments;
            List <Transaction> transactionList = new List <Transaction>();
            Transaction        trans           = new Transaction();

            trans.amount = AmountTest.GetAmount();
            transactionList.Add(trans);
            pay.transactions = transactionList;
            pay.payer        = payer;
            Payment paymnt = pay.Create(TestingUtil.GetApiContext());

            return(paymnt);
        }
예제 #8
0
        public void OrderGetTest()
        {
            var orderId = "O-2HT09787H36911800";
            var order   = Order.Get(TestingUtil.GetApiContext(), orderId);

            Assert.AreEqual(orderId, order.id);
        }
예제 #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;
            }
        }
예제 #10
0
        public void WebProfileGetListTest()
        {
            try
            {
                // Create a new profile
                var apiContext  = TestingUtil.GetApiContext();
                var profileName = Guid.NewGuid().ToString();
                var profile     = WebProfileTest.GetWebProfile();
                profile.name = profileName;
                var createdProfile = profile.Create(apiContext);

                // Get the list of profiles
                var profiles = WebProfile.GetList(apiContext);
                Assert.IsNotNull(profiles);
                Assert.IsTrue(profiles.Count > 0);

                // Delete the profile
                profile.id = createdProfile.id;
                profile.Delete(apiContext);
            }
            finally
            {
                TestingUtil.RecordConnectionDetails();
            }
        }
예제 #11
0
        public void PlanUpdateTest()
        {
            var apiContext = TestingUtil.GetApiContext();

            // Get a test plan for updating purposes.
            var plan        = GetPlan();
            var createdPlan = plan.Create(TestingUtil.GetApiContext());
            var planId      = createdPlan.id;

            // Create the patch request and update the description to a random value.
            var updatedDescription = Guid.NewGuid().ToString();
            var patch = new Patch();

            patch.op    = "replace";
            patch.path  = "/";
            patch.value = new Plan()
            {
                description = updatedDescription
            };
            var patchRequest = new PatchRequest();

            patchRequest.Add(patch);

            // Update the plan.
            createdPlan.Update(apiContext, patchRequest);

            // Verify the plan was updated successfully.
            var updatedPlan = Plan.Get(apiContext, planId);

            Assert.AreEqual(planId, updatedPlan.id);
            Assert.AreEqual(updatedDescription, updatedPlan.description);
        }
예제 #12
0
 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"));
 }
예제 #13
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);
            }
            finally
            {
                TestingUtil.RecordConnectionDetails();
            }
        }
예제 #14
0
        public void WebProfileDeleteTest()
        {
            try
            {
                var apiContext = TestingUtil.GetApiContext();
                this.RecordConnectionDetails();

                // Create a new profile
                var profileName = Guid.NewGuid().ToString();
                var profile     = WebProfileTest.GetWebProfile();
                profile.name = profileName;
                var createdProfile = profile.Create(apiContext);
                this.RecordConnectionDetails();

                // Get the profile object for the new profile
                profile = WebProfile.Get(apiContext, createdProfile.id);
                this.RecordConnectionDetails();

                // Delete the profile
                profile.Delete(apiContext);
                this.RecordConnectionDetails();

                Assert.AreEqual(204, (int)PayPalResource.LastResponseDetails.Value.StatusCode);
            }
            catch (ConnectionException)
            {
                this.RecordConnectionDetails(false);
                throw;
            }
        }
예제 #15
0
 public static PayoutBatch CreateSingleSynchronousPayoutBatch()
 {
     return(Payout.Create(TestingUtil.GetApiContext(), new Payout
     {
         sender_batch_header = new PayoutSenderBatchHeader
         {
             sender_batch_id = "batch_" + System.Guid.NewGuid().ToString().Substring(0, 8),
             email_subject = "You have a Payout!"
         },
         items = new List <PayoutItem>
         {
             new PayoutItem
             {
                 recipient_type = PayoutRecipientType.EMAIL,
                 amount = new Currency
                 {
                     value = "1.0",
                     currency = "USD"
                 },
                 note = "Thanks for the payment!",
                 sender_item_id = "2014031400023",
                 receiver = "*****@*****.**"
             }
         }
     },
                          true));
 }
예제 #16
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;
            }
        }
예제 #17
0
        public void PaymentListHistoryTest()
        {
            var context        = TestingUtil.GetApiContext();
            var paymentHistory = Payment.List(context, count: 10);

            Assert.AreEqual(10, paymentHistory.count);
        }
예제 #18
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;
            }
        }
예제 #19
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;
            }
        }
예제 #20
0
        public void WebhookEventValidateReceivedEventInvalidSignatureTest()
        {
            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", "GsFK/0+kl1nrj4N0x36rzx6uRNOKrlCTLSfxcPdwP+zoBlo/8w+0F9fmoSJgnDDOiJ7jK6Y3xIAt4kxxH+RLbWv0v4G1+w3Cp2UIRQ61s7KVdW6tWhZtNkxZfgQXHeL5/0XrJ43091GM1VHOuagGB5ta9FPL/MYtamTP01vNBRO6H3O0tuYNDXDPTyzDtfS3vi638/Trvtr051CFxCCcdRQjDWL1eJyCVTPDEbzAqnKjEHCkasVvxVFIDBaIy28Ee4FXd9ynwVfqwG6sRSofCgVe7VhmyVb2WSlUyHHaoh0dgjijoqDZmwvl14KMAU80kt7eRUo6jvNKzIolJLByvg==" },
                { "Paypal-Transmission-Id", "f0192050-80e7-11e9-a416-b554c1da3649" },
                { "Paypal-Auth-Algo", "SHA256withRSA" },
                { "Paypal-Transmission-Time", "2019-05-28T01:28:46Z" }
            };
            var webhookId    = "3RN13029J36659323";
            var apiContext   = TestingUtil.GetApiContext();
            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)
            };

            Assert.Throws <PaymentsException>(() => verification.Post(apiContext));
        }
예제 #21
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);
     }
     finally
     {
         TestingUtil.RecordConnectionDetails();
     }
 }
예제 #22
0
 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"));
 }
예제 #23
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));
            }
            finally
            {
                TestingUtil.RecordConnectionDetails();
            }
        }
예제 #24
0
        public void WebhookEventValidateReceivedEventInvalidBodyTest()
        {
            var requestBody    = "{\"id\":\"XX-XXX266712B616591M-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 webhookId    = "3RN13029J36659323";
            var apiContext   = TestingUtil.GetApiContext();
            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)
            };

            Assert.Throws <PaymentsException>(() => verification.Post(apiContext));
        }
        public void WebProfileGetListTest()
        {
            var profiles = WebProfile.GetList(TestingUtil.GetApiContext());

            Assert.IsNotNull(profiles);
            Assert.IsTrue(profiles.Count > 0);
        }
예제 #26
0
        public void PayoutCreateAndGetTest()
        {
            try
            {
                var apiContext = TestingUtil.GetApiContext();
                this.RecordConnectionDetails();

                var payout = PayoutTest.GetPayout();
                var payoutSenderBatchId = "batch_" + System.Guid.NewGuid().ToString().Substring(0, 8);
                payout.sender_batch_header.sender_batch_id = payoutSenderBatchId;
                var createdPayout = payout.Create(apiContext, false);
                this.RecordConnectionDetails();

                Assert.IsNotNull(createdPayout);
                Assert.IsTrue(!string.IsNullOrEmpty(createdPayout.batch_header.payout_batch_id));
                Assert.AreEqual(payoutSenderBatchId, createdPayout.batch_header.sender_batch_header.sender_batch_id);

                var payoutBatchId   = createdPayout.batch_header.payout_batch_id;
                var retrievedPayout = Payout.Get(apiContext, payoutBatchId);
                this.RecordConnectionDetails();

                Assert.IsNotNull(payout);
                Assert.AreEqual(payoutBatchId, retrievedPayout.batch_header.payout_batch_id);
            }
            catch (ConnectionException)
            {
                this.RecordConnectionDetails(false);
                throw;
            }
        }
예제 #27
0
        public void InvoiceQrCodeTest()
        {
            try
            {
                var apiContext = TestingUtil.GetApiContext();
                this.RecordConnectionDetails();

                var invoice        = GetInvoice();
                var createdInvoice = invoice.Create(apiContext);
                this.RecordConnectionDetails();

                var qrCode = Invoice.QrCode(apiContext, createdInvoice.id);
                this.RecordConnectionDetails();

                Assert.IsNotNull(qrCode);
                Assert.IsTrue(!string.IsNullOrEmpty(qrCode.image));

                createdInvoice.Delete(apiContext);
                this.RecordConnectionDetails();
            }
            catch (ConnectionException)
            {
                this.RecordConnectionDetails(false);
            }
        }
예제 #28
0
        public void PaymentVerifyCreatePayPalPaymentForOrderResponse()
        {
            try
            {
                var deserializationErrors = new List <string>();
                JsonFormatter.DeserializationError += (e) => { deserializationErrors.Add(e.Message); };

                var payment        = GetPaymentUsingPayPal("order");
                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("created", createdPayment.state);
                Assert.IsTrue(createdPayment.id.StartsWith("PAY-"));
                Assert.IsTrue(!string.IsNullOrEmpty(createdPayment.token));

                // Verify the expected HATEOAS links: self, approval_url, & execute
                Assert.AreEqual(3, createdPayment.links.Count);
                Assert.IsNotNull(createdPayment.GetHateoasLink(BaseConstants.HateoasLinkRelations.Self));
                Assert.IsNotNull(createdPayment.GetHateoasLink(BaseConstants.HateoasLinkRelations.ApprovalUrl));
                Assert.IsNotNull(createdPayment.GetHateoasLink(BaseConstants.HateoasLinkRelations.Execute));
            }
            finally
            {
                TestingUtil.RecordConnectionDetails();
            }
        }
예제 #29
0
        public void WebhookCreateAndGetTest()
        {
            try
            {
                var apiContext = TestingUtil.GetApiContext();
                this.RecordConnectionDetails();

                var webhook = WebhookTest.GetWebhook();
                var url     = "https://" + Guid.NewGuid().ToString() + ".com/paypal_webhooks";
                webhook.url = url;
                var createdWebhook = webhook.Create(apiContext);
                this.RecordConnectionDetails();

                Assert.IsNotNull(createdWebhook);
                Assert.IsTrue(!string.IsNullOrEmpty(createdWebhook.id));

                var webhookId        = createdWebhook.id;
                var retrievedWebhook = Webhook.Get(apiContext, webhookId);
                this.RecordConnectionDetails();

                Assert.IsNotNull(retrievedWebhook);
                Assert.AreEqual(webhookId, retrievedWebhook.id);
                Assert.AreEqual(url, retrievedWebhook.url);

                // Cleanup
                retrievedWebhook.Delete(apiContext);
                this.RecordConnectionDetails();
            }
            catch (ConnectionException)
            {
                this.RecordConnectionDetails(false);
                throw;
            }
        }
예제 #30
0
        public void AuthorizationGetTest()
        {
            try
            {
                var apiContext = TestingUtil.GetApiContext();
                this.RecordConnectionDetails();

                var pay = PaymentTest.CreatePaymentAuthorization(apiContext);
                this.RecordConnectionDetails();

                Assert.NotNull(pay);
                Assert.NotNull(pay.transactions);
                Assert.True(pay.transactions.Count > 0);
                var transaction = pay.transactions[0];

                Assert.NotNull(transaction.related_resources);
                Assert.True(transaction.related_resources.Count > 0);

                var resource = transaction.related_resources[0];
                Assert.NotNull(resource.authorization);

                var authorizationId = resource.authorization.id;
                var authorize       = Authorization.Get(apiContext, authorizationId);
                this.RecordConnectionDetails();

                Assert.Equal(authorizationId, authorize.id);
            }
            catch (ConnectionException)
            {
                this.RecordConnectionDetails(false);
                throw;
            }
        }