2016-07-21 19 views
0

我一直在研究過去幾個小時,並一直在努力瞭解如何實現Stripe的後端。我不是很有經驗,一些iOS Stripe文檔讓我感到困惑。許多資源建議使用Heroku/PHP並使用Alamofire或AFNetworking來設置後端,但我對它並不是很熟悉。我知道這是一個愚蠢的問題,但我正在努力學習!任何人都可以給我一個解釋如何設置一個簡單的後端/解釋Alamofire或推薦資源如何正確實施Stripe?如何配置Stripe的後端以在Swift應用程序中實現?

+0

你可以找到一個例子iOS後端:https://github.com/stripe/example-ios-backend。此後端可用於綁定中包含的iOS示例:https://github.com/stripe/stripe-ios/tree/master/Example – Ywain

+0

我在下面發佈了一個模糊的答案,但是開始編碼並告訴我們您擁有什麼完成,然後我們可以指出你在正確的方向。 – dylankbuckley

回答

0

我建議學習如何做到這一點,你應該在Javascript/Node.JS中使用它並使用類似Heroku的設置來安裝Express Server。

在iOS方面,我會使用Alamofire,這將允許您輕鬆地從您的Swift應用程序進行API調用。它的實施將是這個樣子(用於創建新的客戶):

let apiURL = "https://YourDomain.com/add-customer" 
let params = ["email": "[email protected]om"] 
let heads = ["Accept": "application/json"] 

Alamofire.request(.POST, apiURL, parameters: params, headers: heads) 
    .responseJSON { response in 
     print(response.request) // original URL request 
     print(response.response) // URL response 
     print(response.data)  // server data 
     print(response.result) // result of response serialization 

     if let JSON = response.result.value { 
      print("JSON: \(JSON)") 
     } 
    } 

在服務器端,假設你使用的快遞有這樣的事情:

app.post('/add-customer', function (req, res) { 
    stripe.customers.create(
     { email: req.body.email }, 
     function(err, customer) { 
      err; // null if no error occured 
      customer; // the created customer object 

      res.json(customer) // Send newly created customer back to client (Swift App) 
     } 
    ); 
}); 
相關問題