2014-12-05 82 views
0

讓我開始說,沒有找到任何教程爲Facebook的asp.net mvc帆布付款教程,我已經設法弄清楚了一段時間,我有一個回調一旦付款經歷了這樣的作品像一個魅力,但我什麼在付款確認後,用戶應該怎麼做。我目前的jquery代碼如下,這是我創建的基於我發現的一些JavaScript代碼,但沒有任何工作,所以我要麼做錯了什麼,或者我只是不知道該怎麼做。請讓我知道該怎麼做才能讓用戶知道付款已完成。如何完成Facebook Canvas付款處理?

更新:這是對我的問題更多的編輯,但我如何將它們重定向到完成頁面,只是給他們一個基本的成功消息。

<script type="text/javascript"> 
     window.fbAsyncInit = function() { 
      FB.init({ 
       appId: '@Microsoft.AspNet.Facebook.GlobalFacebookConfiguration.Configuration.AppId', 
       status: true, 
       cookie: true, 
       xfbml: true 
      }); 

      function buy() { 
       var obj = { 
        method: 'pay', 
        action: 'purchaseitem', 
        product: 'https://website.net/product.html', 
        request_id: '@ViewBag.HashKey' 
       }; 

       FB.ui(obj, function (data) { 
        $.ajax({ 
         type: "GET", 
         dataType: "json", 
         contentType: "application/json", 
         url: "/Home/finishOrder", 
         data: data, 
         async: true 
        }); 
       }, callback); 
      } 
      buy(); 

     }; 

     function callback(data) { 
      if (!data) { 
       alert("There was an error processing your payment. Please try again!"); 
       return; 
      } 

      console.log('Verifying payment', data); 

      if (data.error_code) { 
       if (data.error_code != 1383010) { 
        alert("There was an error processing your payment." + data.error_message + " Error code:" + data.error_code); 
       } 
       return; 
      } 

      alert("The payment is successful!"); 
     } 

     // Load the SDK Asynchronously 
     (function (d) { 
      var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; 
      if (d.getElementById(id)) { return; } 
      js = d.createElement('script'); js.id = id; js.async = true; 
      js.src = "//connect.facebook.net/en_US/all.js"; 
      ref.parentNode.insertBefore(js, ref); 
     }(document)); 
    </script> 

回答

0

事實證明,我試圖將兩個不同的回調函數與我的代碼結合起來。這是我對任何感興趣的人完成的代碼。這將調用一個爲用戶返回消息的方法。

function buy() { 
       var obj = { 
        method: 'pay', 
        action: 'purchaseitem', 
        product: 'https://website.net/product.html', 
        request_id: '@ViewBag.HashKey' 
       }; 

       FB.ui(obj, function (data) { 
        $.ajax({ 
         type: "GET", 
         dataType: "json", 
         contentType: "application/json", 
         url: "/Home/finishOrder", 
         data: data, 
         async: true, 
         success: function (data) { 
          alert(data.message); 
        } 
        }); 
       }); 
      } 
      buy();