Example #1
0
        /// <summary>
        ///     Calculates the payment info via Pushpay, then redirects the user to the secure URL where they can enter their
        ///     payment details
        /// </summary>
        public async Task <AnticipatedPaymentRepresentation> FinalizePayment(string merchantKey)
        {
            // Create a model for PP
            var paymentDetails = new EditAnticipatedPaymentModel();

            paymentDetails.Payer = new PayerDetails {
                EmailAddress = "*****@*****.**", FullName = "Pushpay API"
            };

            // The amount is stored in a config field
            paymentDetails.Fields.Add(new FieldConfigModel
            {
                Key      = "amount",
                Value    = GrandTotal.ToString("0.00"),
                ReadOnly = true
            });

            // Other info
            paymentDetails.Description      = GetBasketContentsDescription();
            paymentDetails.DescriptionTitle = "Fruit purchase";
            paymentDetails.MerchantKey      = merchantKey;
            paymentDetails.Reference        = Guid.NewGuid().ToString();      // Would typically be your own invoice/reference number according to your e-commerce shopping cart
            paymentDetails.ReturnTitle      = "Return to the example site";
            paymentDetails.ReturnUrl        = new WebEnvironment().GetFullUrl("home/paymentcomplete", true);

            // Send to pushpay
            var connection = new PushpayConnection();
            AnticipatedPaymentRepresentation response = await connection.SendPaymentToPushpay(paymentDetails);

            return(response);
        }
        /// <summary>
        ///     Sends the payment details to Pushpay, which returns with a URL where we redirect the user for payment
        /// </summary>
        /// <param name="paymentDetails"></param>
        /// <returns></returns>
        public async Task <AnticipatedPaymentRepresentation> SendPaymentToPushpay(EditAnticipatedPaymentModel paymentDetails)
        {
            ApiClient client = await CreateClient();

            AnticipatedPaymentRepresentation result =
                await client.Init("anticipatedpayments", "Sending payment to Pushpay").SetMethod(RequestMethodTypes.POST).SetContent(paymentDetails).Execute <AnticipatedPaymentRepresentation>();

            return(result);
        }