private void VerifyPaypalCheckout(SubscriberPaymentProviderInfo subscriberPaymentProvider) { string token = Request["token"]; if (subscriberPaymentProvider != null) { string[] userCredentials = subscriberPaymentProvider.PaymentProviderProperties.Split(','); PaypalUserCredentials cred = new PaypalUserCredentials(userCredentials[0], userCredentials[1], userCredentials[2]); PaypalApi.UseSandbox = (userCredentials.Length == 3 || (userCredentials.Length > 3 && Convert.ToBoolean(userCredentials[3]) == true)); string response = PaypalApi.GetExpressCheckoutDetails(cred, token); PaypalCommonResponse ppCommon = new PaypalCommonResponse(response); if (ppCommon.Ack == PaypalAckType.Success) { // TODO: Paypal Payerinfo auswerten ? PaypalPayerInfo payer = new PaypalPayerInfo(response); CustomerPaymentProviderInfo customerPaymentProvider = Controller.GetCustomerPaymentProvider(MainControl.Cart.CustomerPaymentProviderID); // Save token and payerid in customerpaymentprovider for later confirmation of payment in paypal customerPaymentProvider.PaymentProviderValues = ppCommon.Token + "," + payer.PayerId; Controller.UpdateCustomerPaymentProvider(customerPaymentProvider); Response.Redirect(Globals.NavigateURL(TabId, "", "action=" + MainControl.GetNextAction())); } else { string message = ""; foreach (PaypalError error in ppCommon.Errors) { message += String.Format("ErrorNo:{0} Message {1}<br/>\r\n", error.ErrorNo, error.LongMessage); } MainControl.ErrorText += message; } } }
private void StartPaypalCheckout(string properties, int paymentProviderId) { string[] props = properties.Split(','); PaypalApi.UseSandbox = (props.Length == 3 || (props.Length > 3 && Convert.ToBoolean(props[3]) == true)); PaypalUserCredentials cred = new PaypalUserCredentials(props[0], props[1], props[2]); PaypalSetExpressCheckoutParameters param = new PaypalSetExpressCheckoutParameters() { CancelUrl = Globals.NavigateURL(this.TabId, "", "action=payment", "provider=" + paymentProviderId.ToString(), "result=cancel"), ReturnUrl = Globals.NavigateURL(this.TabId, "", "action=payment", "provider=" + paymentProviderId.ToString(), "result=success"), NoShipping = 1, // PayPal does not display shipping address fields whatsoever. AllowNote = 0, // The buyer is unable to enter a note to the merchant. }; PaypalPaymentDetails request = new PaypalPaymentDetails(); CartInfo cart = Controller.GetCart(PortalId, MainControl.CartId); request.Amt = cart.OrderTotal + cart.AdditionalTotal + cart.OrderTax + cart.AdditionalTax; request.TaxAmt = cart.OrderTax + cart.AdditionalTax; request.ItemAmt = cart.OrderTotal + cart.AdditionalTotal; request.InvNum = cart.CartID.ToString(); request.CurrencyCode = "EUR"; List <PaypalPaymentDetailsItem> items = new List <PaypalPaymentDetailsItem>(); PaypalPaymentDetailsItem item = new PaypalPaymentDetailsItem(); item.Amt = request.ItemAmt; item.Name = String.Format(Localization.GetString("PPCart.Text", this.LocalResourceFile), Controller.GetStoreSettings(PortalId)["VendorName"] ?? "BBStore"); List <CartProductInfo> products = Controller.GetCartProducts(cart.CartID); item.Desc = ""; foreach (CartProductInfo product in products) { item.Desc += string.Format("{0} {1}\r\n", (product.Quantity % 1 == 0 ? (int)product.Quantity : product.Quantity), product.Name); } item.TaxAmt = request.TaxAmt; items.Add(item); string response = PaypalApi.SetExpressCheckout(cred, request, items, param); PaypalCommonResponse ppCommon = new PaypalCommonResponse(response); if (ppCommon.Ack == PaypalAckType.Success) { if (PaypalApi.UseSandbox) { Response.Redirect("https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=" + ppCommon.Token); } else { Response.Redirect("https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=" + ppCommon.Token); } } else { string message = ""; foreach (PaypalError error in ppCommon.Errors) { message += String.Format("ErrorNo:{0} Message {1}<br/>\r\n", error.ErrorNo, error.LongMessage); } MainControl.ErrorText += message; } }