PayPal Plus保留在自己的页面上

时间:2017-07-14 17:26:22

标签: asp.net paypal

我在ASP.NET中实现了一个小型的PayPal PLUS演示:

    protected void Page_Load(object sender, EventArgs e)
    {
        var config = ConfigManager.Instance.GetProperties();

        config.Add("clientId", "XXXXXXXXXXXXXXXXXXXXXXXXX");
        config.Add("clientSecret", "XXXXXXXXXXXXXXXXXXXXXXXXX");
        config.Add("mode", "sandbox");

        var accessToken = new OAuthTokenCredential(config).GetAccessToken();
        var apiContext = new APIContext(accessToken);
        var itemList = new ItemList() { items = new List<Item>() { new Item() { name = "Item Name", currency = "USD", price = "15", quantity = "5", sku = "sku" } } };
        var payer = new Payer() { payment_method = "paypal" };
        var baseURI = Request.Url.Scheme + "://" + Request.Url.Authority + "/PaymentWithPayPal.aspx?";
        var guid = Convert.ToString((new Random()).Next(100000));
        var redirectUrl = baseURI + "guid=" + guid;
        var redirUrls = new RedirectUrls() { cancel_url = redirectUrl + "&cancel=true", return_url = redirectUrl };
        var details = new Details() { tax = "15", shipping = "10", subtotal = "75" };
        var amount = new Amount() { currency = "USD", total = "100.00", details = details };
        var transactionList = new List<Transaction> { new Transaction() { description = "Transaction description.", invoice_number = new Random().Next(999999).ToString(), amount = amount, item_list = itemList } };
        var payment = new Payment() { intent = "sale", payer = payer, transactions = transactionList, redirect_urls = redirUrls };
        var createdPayment = payment.Create(apiContext);
        var approval_url = createdPayment.links.FirstOrDefault(x => x.rel == "approval_url").href;
        hfApprovalUrl.Value = approval_url;
    }



 <asp:HiddenField runat="server" id="hfApprovalUrl"/>
    <script src="https://www.paypalobjects.com/webstatic/ppplus/ppplus.min.js" type="text/javascript"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <div id="ppplus"></div>
    <script type="application/javascript">

        var approval_url = $('#hfApprovalUrl').val();

        var ppp = PAYPAL.apps.PPP({
            "approvalUrl": approval_url,
            "placeholder": "ppplus",
            "mode": "sandbox",
            "country": "DE"
        });

    </script>

它的工作到目前为止,但如果选择付费选项(例如信用卡),我将被重定向到PayPal。我希望用户在我自己的页面上。我怎样才能做到这一点? 谢谢! 扬

0 个答案:

没有答案