Пример #1
0
        public async Task RetrievePaymentDetailsAsync_WhenHasNoDetails_ReturnsError()
        {
            // Arrange
            var paymentRequest = new PaymentGetRequest
            {
                PaymentId = Guid.NewGuid()
            };

            this.paymentRepositoryMock
            .Setup(s => s.GetByIdAsync(It.IsAny <Guid>()))
            .ReturnsAsync(default(Payment));

            // Act
            var result = await this.target.RetrievePaymentDetailsAsync(paymentRequest);

            // Assert
            Assert.False(result.Success);
            Assert.True(result.Errors.ContainsKey("paymentDetails"));

            this.paymentRepositoryMock
            .Verify(v => v.GetByIdAsync(It.IsAny <Guid>()), Times.Once);
            this.loggerMock
            .Verify(v => v.Log(
                        It.Is <LogLevel>(l => l == LogLevel.Information),
                        It.IsAny <EventId>(),
                        It.Is <It.IsAnyType>((v, t) => v.ToString().Equals("Payment details not found.")),
                        It.IsAny <Exception>(),
                        It.Is <Func <It.IsAnyType, Exception, string> >((v, t) => true)), Times.Once);
        }
Пример #2
0
        public async Task RetrievePaymentDetailsAsync_HappyJourney_ReturnsDetails()
        {
            // Arrange
            var paymentRequest = new PaymentGetRequest
            {
                PaymentId = Guid.NewGuid()
            };

            this.paymentRepositoryMock
            .Setup(s => s.GetByIdAsync(It.IsAny <Guid>()))
            .ReturnsAsync(new Payment {
                Id = Guid.NewGuid()
            });

            // Act
            var result = await this.target.RetrievePaymentDetailsAsync(paymentRequest);

            // Assert
            Assert.True(result.Success);
            Assert.Equal(0, result.Errors.Count);
            Assert.NotNull(result.Result);

            this.paymentRepositoryMock
            .Verify(v => v.GetByIdAsync(It.IsAny <Guid>()), Times.Once);
        }
Пример #3
0
        public async Task GetAsync_Successful_ReturnsOk()
        {
            // Arrange
            var request = new PaymentGetRequest
            {
                PaymentId = Guid.NewGuid()
            };

            this.paymentServiceMock
            .Setup(s => s.RetrievePaymentDetailsAsync(request))
            .ReturnsAsync(new BaseResult <PaymentGetResult>(new PaymentGetResult()));

            // Act
            var result = await this.target.GetAsync(request);

            var objResult     = result as OkObjectResult;
            var paymentResult = objResult.Value as BaseResult <PaymentGetResult>;

            // Assert
            Assert.NotNull(paymentResult.Result);
            Assert.True(paymentResult.Success);
            Assert.Empty(paymentResult.Errors);

            this.paymentServiceMock
            .Verify(v => v.RetrievePaymentDetailsAsync(request), Times.Once);
        }
Пример #4
0
        public async Task GetAsync_Unsuccessful_ReturnsNotFound()
        {
            // Arrange
            var request = new PaymentGetRequest
            {
                PaymentId = Guid.NewGuid()
            };

            this.paymentServiceMock
            .Setup(s => s.RetrievePaymentDetailsAsync(request))
            .ReturnsAsync(new BaseResult <PaymentGetResult>(errors: new Dictionary <string, string> {
                { "someError", "someDescription" }
            }));

            // Act
            var result = await this.target.GetAsync(request);

            var objResult     = result as NotFoundObjectResult;
            var paymentResult = objResult.Value as BaseResult <PaymentGetResult>;

            // Assert
            Assert.Null(paymentResult.Result);
            Assert.False(paymentResult.Success);
            Assert.Single(paymentResult.Errors);

            this.paymentServiceMock
            .Verify(v => v.RetrievePaymentDetailsAsync(request), Times.Once);
        }
Пример #5
0
 /// <summary>
 /// Gets the request payer value for the specified bucket
 /// </summary>
 public String PaymentGet(String bucketName)
 {
     using (PaymentGetRequest paymentGetRequest = new PaymentGetRequest(bucketName))
         using (PaymentGetResponse paymentGetResponse = this.service.PaymentGet(paymentGetRequest))
         {
             return(paymentGetResponse.StreamResponseToString());
         }
 }
Пример #6
0
        public async Task <IActionResult> GetAsync([FromQuery] PaymentGetRequest paymentGetRequest)
        {
            var result = await this.paymentService.RetrievePaymentDetailsAsync(paymentGetRequest);

            if (result.Success)
            {
                return(this.Ok(result));
            }

            return(this.NotFound(result));
        }
Пример #7
0
        /// <summary>
        /// Retrieves the details of a single existing payment.
        /// </summary>
        /// <param name="identity">Unique identifier, beginning with "PM".</param>
        /// <param name="request">An optional `PaymentGetRequest` representing the query parameters for this get request.</param>
        /// <param name="customiseRequestMessage">An optional `RequestSettings` allowing you to configure the request</param>
        /// <returns>A single payment resource</returns>
        public Task <PaymentResponse> GetAsync(string identity, PaymentGetRequest request = null, RequestSettings customiseRequestMessage = null)
        {
            request = request ?? new PaymentGetRequest();
            if (identity == null)
            {
                throw new ArgumentException(nameof(identity));
            }

            var urlParams = new List <KeyValuePair <string, object> >
            {
                new KeyValuePair <string, object>("identity", identity),
            };

            return(_goCardlessClient.ExecuteAsync <PaymentResponse>(HttpMethod.Get, "/payments/:identity", urlParams, request, null, null, customiseRequestMessage));
        }
Пример #8
0
        public static async Task <Payment> GetPayment(string paymentId)
        {
            var client = PayPalConfiguration.GetClient();

            PaymentGetRequest request = new PaymentGetRequest(paymentId);

            try
            {
                //TODO - ASYNC
                HttpResponse response = await client.Execute(request);

                var statusCode = response.StatusCode;
                return(response.Result <Payment>());
            }
            catch (HttpException httpException)
            {
                var statusCode = httpException.StatusCode;
                var debugId    = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault();

                throw httpException;
            }
        }
Пример #9
0
        public async Task <BaseResult <PaymentGetResult> > RetrievePaymentDetailsAsync(PaymentGetRequest paymentGetRequest)
        {
            var result = new BaseResult <PaymentGetResult>();

            var payment = await this.paymentRepository.GetByIdAsync(paymentGetRequest.PaymentId);

            if (payment != null)
            {
                result.Result = payment.ToGetResult();
                return(result);
            }

            this.logger.LogInformation("Payment details not found.", new
            {
                Class  = nameof(PaymentService),
                Method = nameof(RetrievePaymentDetailsAsync),
                paymentGetRequest.PaymentId
            });

            result.Errors.Add("paymentDetails", "Payment details not found.");
            return(result);
        }
Пример #10
0
 /// <summary>
 /// Gets a payment request configuration
 /// </summary>
 public PaymentGetResponse PaymentGet(PaymentGetRequest request)
 {
     return(Invoke <PaymentGetResponse>(request));
 }
Пример #11
0
        static void DemonstrateThreeSharp()
        {
            Console.WriteLine("===========================================");
            Console.WriteLine("Demonstrating the ThreeSharp Library");
            Console.WriteLine("===========================================");

            ThreeSharpConfig config = new ThreeSharpConfig();

            config.AwsAccessKeyID     = awsAccessKeyId;
            config.AwsSecretAccessKey = awsSecretAccessKey;
            config.IsSecure           = false;

            IThreeSharp service = new ThreeSharpQuery(config);

            // Convert the bucket name to lowercase for vanity domains.
            // the bucket must be lower case since DNS is case-insensitive.
            Random r = new Random();
            string testBucketName  = awsAccessKeyId.ToLower() + "-test-bucket" + r.Next(50000).ToString();;
            string testBucketName2 = awsAccessKeyId.ToLower() + "-test-bucket" + r.Next(50000).ToString();;
            string stringKeyName   = "StringObject";


            Console.WriteLine("\n----- Creating Bucket " + testBucketName + " -----");
            using (BucketAddRequest request = new BucketAddRequest(testBucketName))
                using (BucketAddResponse response = service.BucketAdd(request))
                { }
            Console.WriteLine("\npress enter >");
            Console.ReadLine();

            Console.WriteLine("\n----- Listing Bucket " + testBucketName + " -----");
            using (BucketListRequest request = new BucketListRequest(testBucketName))
                using (BucketListResponse response = service.BucketList(request))
                {
                    Console.WriteLine(response.StreamResponseToString());
                }
            Console.WriteLine("\npress enter >");
            Console.ReadLine();

            Console.WriteLine("\n----- Creating Bucket " + testBucketName2 + " -----");
            using (BucketAddRequest request = new BucketAddRequest(testBucketName2))
                using (BucketAddResponse response = service.BucketAdd(request))
                { }
            Console.WriteLine("\npress enter >");
            Console.ReadLine();

            Console.WriteLine("\n----- Listing Bucket " + testBucketName2 + " -----");
            using (BucketListRequest request = new BucketListRequest(testBucketName2))
                using (BucketListResponse response = service.BucketList(request))
                {
                    Console.WriteLine(response.StreamResponseToString());
                }
            Console.WriteLine("\npress enter >");
            Console.ReadLine();

            Console.WriteLine("\n----- Adding String Object to " + testBucketName + " -----");
            using (ObjectAddRequest request = new ObjectAddRequest(testBucketName, stringKeyName))
            {
                request.LoadStreamWithString("This is a string object.");
                using (ObjectAddResponse response = service.ObjectAdd(request))
                { }
            }
            Console.WriteLine("\npress enter >");
            Console.ReadLine();

            Console.WriteLine("\n----- Getting String Object -----");
            using (ObjectGetRequest request = new ObjectGetRequest(testBucketName, stringKeyName))
            {
                using (ObjectGetResponse response = service.ObjectGet(request))
                {
                    Console.WriteLine(response.StreamResponseToString());
                }
            }
            Console.WriteLine("\npress enter >");
            Console.ReadLine();

            Console.WriteLine("\n----- Copying String Object to " + testBucketName2 + " -----");
            using (ObjectCopyRequest request = new ObjectCopyRequest(testBucketName, stringKeyName, testBucketName2, stringKeyName + "Copy"))
                using (ObjectCopyResponse response = service.ObjectCopy(request))
                { }
            Console.WriteLine("\npress enter >");
            Console.ReadLine();

            Console.WriteLine("\n----- Listing Bucket " + testBucketName2 + " -----");
            using (BucketListRequest request = new BucketListRequest(testBucketName2))
                using (BucketListResponse response = service.BucketList(request))
                {
                    Console.WriteLine(response.StreamResponseToString());
                }
            Console.WriteLine("\npress enter >");
            Console.ReadLine();

            Console.WriteLine("\n----- Getting RequestPaymentConfiguration for " + testBucketName2 + " -----");
            using (PaymentGetRequest request = new PaymentGetRequest(testBucketName2))
                using (PaymentGetResponse response = service.PaymentGet(request))
                {
                    Console.WriteLine(response.StreamResponseToString());
                }
            Console.WriteLine("\npress enter >");
            Console.ReadLine();

            Console.WriteLine("\n----- Changing RequestPaymentConfiguration for " + testBucketName2 + " -----");
            using (PaymentChangeRequest request = new PaymentChangeRequest(testBucketName2, PaymentChangeRequest.Payer.Requester))
                using (PaymentChangeResponse response = service.PaymentChange(request))
                { }

            Console.WriteLine("\n----- Getting RequestPaymentConfiguration (again) for " + testBucketName2 + " -----");
            using (PaymentGetRequest request = new PaymentGetRequest(testBucketName2))
                using (PaymentGetResponse response = service.PaymentGet(request))
                {
                    Console.WriteLine(response.StreamResponseToString());
                }
            Console.WriteLine("\npress enter >");
            Console.ReadLine();

            Console.WriteLine("\n----- Changing RequestPaymentConfiguration for " + testBucketName2 + " -----");
            using (PaymentChangeRequest request = new PaymentChangeRequest(testBucketName2, PaymentChangeRequest.Payer.BucketOwner))
                using (PaymentChangeResponse response = service.PaymentChange(request))
                { }

            Console.WriteLine("\n----- Getting Copied String Object -----");
            using (ObjectGetRequest request = new ObjectGetRequest(testBucketName2, stringKeyName + "Copy"))
            {
                using (ObjectGetResponse response = service.ObjectGet(request))
                {
                    Console.WriteLine(response.StreamResponseToString());
                }
            }
            Console.WriteLine("\npress enter >");
            Console.ReadLine();


            Console.WriteLine("\n----- Streaming File Object -----");
            using (ObjectAddRequest request = new ObjectAddRequest(testBucketName, uploadFile))
            {
                request.LoadStreamWithFile(uploadPath + uploadFile);
                using (ObjectAddResponse response = service.ObjectAdd(request))
                { }
            }
            Console.WriteLine("\npress enter >");
            Console.ReadLine();

            Console.WriteLine("\n----- Streaming/Encrypting File Object -----");
            using (ObjectAddRequest request = new ObjectAddRequest(testBucketName, uploadFile + "Encrypted"))
            {
                request.LoadStreamWithFile(uploadPath + uploadFile);
                request.EncryptStream(encryptionKey, encryptionIV);
                using (ObjectAddResponse response = service.ObjectAdd(request))
                { }
            }
            Console.WriteLine("\npress enter >");
            Console.ReadLine();

            Console.WriteLine("\n----- Listing Bucket " + testBucketName + " -----");
            using (BucketListRequest request = new BucketListRequest(testBucketName))
                using (BucketListResponse response = service.BucketList(request))
                {
                    Console.WriteLine(response.StreamResponseToString());
                }
            Console.WriteLine("\npress enter >");
            Console.ReadLine();

            Console.WriteLine("\n----- Streaming File to Disk -----");
            using (ObjectGetRequest request = new ObjectGetRequest(testBucketName, uploadFile))
                using (ObjectGetResponse response = service.ObjectGet(request))
                {
                    response.StreamResponseToFile(downloadPath + uploadFile);
                }
            Console.WriteLine("\npress enter >");
            Console.ReadLine();

            Console.WriteLine("\n----- Streaming/Decrypting File to Disk -----");
            using (ObjectGetRequest request = new ObjectGetRequest(testBucketName, uploadFile + "Encrypted"))
                using (ObjectGetResponse response = service.ObjectGet(request))
                {
                    response.DecryptStream(encryptionKey, encryptionIV);
                    response.StreamResponseToFile(downloadPath + "decrypted-" + uploadFile);
                }
            Console.WriteLine("\npress enter >");
            Console.ReadLine();

            Console.WriteLine("\n----- Query String Authorization Example -----");
            using (UrlGetRequest request = new UrlGetRequest(testBucketName, uploadFile))
            {
                request.ExpiresIn = 60 * 1000;
                using (UrlGetResponse response = service.UrlGet(request))
                {
                    Console.WriteLine("Try this url in your web browser (it will only work for 60 seconds)\n");
                    Console.WriteLine(response.StreamResponseToString());
                }
            }
            Console.WriteLine("\npress enter >");
            Console.ReadLine();

            Console.WriteLine("\n----- Adding String Object with Metadata and Public Read ACL -----");
            using (ObjectAddRequest request = new ObjectAddRequest(testBucketName, stringKeyName + "Public"))
            {
                request.LoadStreamWithString("This is a publicly readable test.");
                request.MetaData.Add("blah", "foo");
                request.Headers.Add("x-amz-acl", "private");
                //request.Headers.Add("x-amz-acl", "public-read");
                //request.Headers.Add("x-amz-acl", "public-read-write");
                //request.Headers.Add("x-amz-acl", "authenticated-read");
                using (ObjectAddResponse response = service.ObjectAdd(request))
                { }
            }
            Console.WriteLine("\npress enter >");
            Console.ReadLine();

            Console.WriteLine("\n----- Getting Object's ACL -----");
            using (ACLGetRequest request = new ACLGetRequest(testBucketName, stringKeyName + "Public"))
                using (ACLGetResponse response = service.ACLGet(request))
                {
                    string output = response.StreamResponseToString();
                    Console.WriteLine(output);
                }
            Console.WriteLine("\npress enter >");
            Console.ReadLine();

            Console.WriteLine("\n----- Changing Object's ACL -----");
            using (ACLChangeRequest request = new ACLChangeRequest(testBucketName, stringKeyName + "Public", "public-read"))
                using (ACLChangeResponse response = service.ACLChange(request))
                { }
            Console.WriteLine("\npress enter >");
            Console.ReadLine();

            Console.WriteLine("\n----- Getting Object's ACL -----");
            using (ACLGetRequest request = new ACLGetRequest(testBucketName, stringKeyName + "Public"))
                using (ACLGetResponse response = service.ACLGet(request))
                {
                    string output = response.StreamResponseToString();
                    Console.WriteLine(output);
                }
            Console.WriteLine("\npress enter >");
            Console.ReadLine();

            Console.WriteLine("\n----- Deleting Objects -----");
            using (ObjectDeleteRequest request = new ObjectDeleteRequest(testBucketName, stringKeyName))
                using (ObjectDeleteResponse response = service.ObjectDelete(request))
                { }
            using (ObjectDeleteRequest request = new ObjectDeleteRequest(testBucketName2, stringKeyName + "Copy"))
                using (ObjectDeleteResponse response = service.ObjectDelete(request))
                { }
            using (ObjectDeleteRequest request = new ObjectDeleteRequest(testBucketName, uploadFile))
                using (ObjectDeleteResponse response = service.ObjectDelete(request))
                { }
            using (ObjectDeleteRequest request = new ObjectDeleteRequest(testBucketName, uploadFile + "Encrypted"))
                using (ObjectDeleteResponse response = service.ObjectDelete(request))
                { }
            using (ObjectDeleteRequest request = new ObjectDeleteRequest(testBucketName, stringKeyName + "Public"))
                using (ObjectDeleteResponse response = service.ObjectDelete(request))
                { }

            Console.WriteLine("\npress enter >");
            Console.ReadLine();

            Console.WriteLine("\n----- Listing Bucket " + testBucketName + " -----");
            using (BucketListRequest request = new BucketListRequest(testBucketName))
                using (BucketListResponse response = service.BucketList(request))
                {
                    Console.WriteLine(response.StreamResponseToString());
                }
            Console.WriteLine("\npress enter >");
            Console.ReadLine();

            Console.WriteLine("\n----- Listing Bucket " + testBucketName2 + " -----");
            using (BucketListRequest request = new BucketListRequest(testBucketName2))
                using (BucketListResponse response = service.BucketList(request))
                {
                    Console.WriteLine(response.StreamResponseToString());
                }
            Console.WriteLine("\npress enter >");
            Console.ReadLine();

            Console.WriteLine("\n----- Listing All My Buckets -----");
            using (BucketListRequest request = new BucketListRequest(null))
                using (BucketListResponse response = service.BucketList(request))
                {
                    Console.WriteLine(response.StreamResponseToString());
                }
            Console.WriteLine("\npress enter >");
            Console.ReadLine();

            Console.WriteLine("\n----- Deleting Bucket " + testBucketName + " -----");
            using (BucketDeleteRequest request = new BucketDeleteRequest(testBucketName))
                using (BucketDeleteResponse response = service.BucketDelete(request))
                { }
            Console.WriteLine("\npress enter >");
            Console.ReadLine();

            Console.WriteLine("\n----- Deleting Bucket " + testBucketName2 + " -----");
            using (BucketDeleteRequest request = new BucketDeleteRequest(testBucketName2))
                using (BucketDeleteResponse response = service.BucketDelete(request))
                { }
            Console.WriteLine("\npress enter >");
            Console.ReadLine();

            Console.WriteLine("\n----- Listing All My Buckets -----");
            using (BucketListRequest request = new BucketListRequest(null))
                using (BucketListResponse response = service.BucketList(request))
                {
                    Console.WriteLine(response.StreamResponseToString());
                }
            Console.WriteLine("\npress enter >");
            Console.ReadLine();

            Console.WriteLine("\nTotal data transfers: " + service.GetTransferInfos().Length.ToString());
            Console.WriteLine("Total bytes uploaded: " + service.GetTotalBytesUploaded().ToString());
            Console.WriteLine("Total bytes downloaded: " + service.GetTotalBytesDownloaded().ToString());
            Console.WriteLine("\npress enter >");
            Console.ReadLine();
        }