【发布时间】:2015-02-10 06:19:07
【问题描述】:
我们在 IOS 应用中使用 PayPal 未来付款。我们需要知道授权未来付款的帐户的电子邮件 ID。我们如何获取授权未来付款的用户的电子邮件 ID。当前用于批准的 API 操作仅返回授权令牌。
【问题讨论】:
标签: ios objective-c paypal
我们在 IOS 应用中使用 PayPal 未来付款。我们需要知道授权未来付款的帐户的电子邮件 ID。我们如何获取授权未来付款的用户的电子邮件 ID。当前用于批准的 API 操作仅返回授权令牌。
【问题讨论】:
标签: ios objective-c paypal
我假设您所指的“未来付款”指的是预先批准的付款......??
设置IPN 解决方案并确保在您的Preapproval API 请求中使用IPNNotificationURL。 IPN 将包含有关交易的更多详细信息,包括付款人电子邮件地址。
Here is a list of the variables you can expect 来自正在创建的 Preapproval 配置文件。您会注意到“sender_email”参数,这正是您要寻找的。p>
这是我在处理 Preapproval 请求后在沙盒中获得的实际 IPN 示例。
Array
(
[max_number_of_payments] => 100
[starting_date] => 2015-03-01T00:00:21.000-08:00
[pin_type] => NOT_REQUIRED
[max_amount_per_payment] => 20.00
[currency_code] => USD
[sender_email] => guy.louzon-buyer@gmail.com
[verify_sign] => AFcWxV21C7fd0v3bYYYRCpSSRl31AiHQSQchSGUInXdtl6zomfkZ7H4C
[test_ipn] => 1
[date_of_month] => 0
[current_number_of_payments] => 0
[preapproval_key] => PA-2M0807730Y425554F
[ending_date] => 2015-12-31T23:59:21.000-08:00
[approved] => true
[transaction_type] => Adaptive Payment PREAPPROVAL
[day_of_week] => NO_DAY_SPECIFIED
[status] => ACTIVE
[current_total_amount_of_all_payments] => 0.00
[current_period_attempts] => 0
[charset] => windows-1252
[payment_period] => 0
[notify_version] => UNVERSIONED
[max_total_amount_of_all_payments] => 2000.00
)
【讨论】:
Ichathan,您将希望利用 mSDK 的 Profile Sharing 功能来获取客户属性并在其中传递未来付款范围以获得这些客户的同意。 iOS SDK 的 PayPalOAuthScopes.h 文件中列出了可用于配置文件共享的可用范围。
【讨论】:
这个answer是正确的,但不详细。
Profile Sharing Mobile Integration 允许用户同意未来的付款以及在一个登录流程中获取电子邮件和其他信息。这是我们使用的 sn-p:
func profileController() -> PayPalProfileSharingViewController {
PayPalMobile.preconnectWithEnvironment(PayPalEnvironmentSandbox)//PayPalEnvironmentNoNetwork)
let scope: Set<String> = Set([kPayPalOAuth2ScopeEmail, kPayPalOAuth2ScopeFuturePayments])
let controller = PayPalProfileSharingViewController(scopeValues: scope, configuration: self.paypalConfiguration!, delegate: self)
return controller!
}
func payPalProfileSharingViewController(profileSharingViewController: PayPalProfileSharingViewController, userDidLogInWithAuthorization profileSharingAuthorization: [NSObject : AnyObject]) {
self.processAuthorization(profileSharingAuthorization)
}
func userDidCancelPayPalProfileSharingViewController(profileSharingViewController: PayPalProfileSharingViewController) {
self.delegate?.didFailPayPalConsent()
}
func processAuthorization(authorization: [NSObject: AnyObject]) {
if let authCode = authorization["response"]?["code"] as? String {
self.delegate?.didSucceedPayPalConsent(authCode)
}
else {
self.delegate?.didFailPayPalConsent()
}
}
编辑:移动控制器为您提供有权访问个人资料信息的身份验证令牌,但您必须从服务器端代码再次调用该信息:
【讨论】:
我就是这样做的。 个人资料分享Paypal Profile Sharing 为我们提供了 Auth Token 这个特定的委托函数被调用
func payPalProfileSharingViewController(profileSharingViewController: PayPalProfileSharingViewController, userDidLogInWithAuthorization profileSharingAuthorization: [NSObject : AnyObject]) {
self.processAuthorization(profileSharingAuthorization)
}
在 authToken 之后,我们需要访问一些服务器端 API。我们也可以通过应用端来实现这一点。我已经从客户端访问了服务器端 api
第一步是创建一个基本的身份验证请求,它将返回一个刷新和访问令牌。 Get Access Token
func generateAccessToken(authCode : String ,block : completionHandler){
let parameters = ["grant_type" : "authorization_code", "response_type" :"token","redirect_uri" : "urn:ietf:wg:oauth:2.0:oob","code":authCode]
let username = AppConstants().kPayPalUserName //APP_ID
let password = AppConstants().kPayPalSecret
let credentialData = "\(username):\(password)".data(using: String.Encoding.utf8)!
let base64Credentials = credentialData.base64EncodedString(options: [])
let headers = ["Authorization": "Basic \(base64Credentials)"]
let customerURL = AppConstants().kPayPalUrl
Alamofire.request(customerURL,
method: .post,
parameters: parameters,
encoding: URLEncoding.default,
headers:headers)
.validate()
.responseJSON { response in
switch response.result {
case .success(let value):
KVNProgress.dismiss(completion: {
block?(true, value as! Dictionary<String, Any>) // get the accessToken
})
// BasicFunctions.displayAlert("Success", needDismiss: false, title: "Task Created Successfully")
case .failure(let responseError):
KVNProgress.dismiss(completion: {
if (responseError != nil) {
BasicFunctions.displayAlert(SERVER_ERROR)
// let json = JSONSerialization
// block!(false,responseError as! Dictionary<String, Any>)
}else{
BasicFunctions.displayAlert(SERVER_ERROR)
}
})
}
}
}
使用访问令牌我们需要点击另一个 CURL 请求,它会给我们所有的用户信息Get User Profile Information
现在使用这个请求,我们可以获得完整的用户信息。访问令牌是从基本身份验证令牌生成的
func getUserProfileInfo(accessToken : String,block : completionHandler){
KVNProgress.show()
let parameters = ["":""]
let headers = ["Authorization": "Bearer " + accessToken]
let customerURL = "https://api.sandbox.paypal.com/v1/identity/openidconnect/userinfo/?schema=openid"
Alamofire.request(customerURL, method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: headers).responseJSON { (response) in
switch response.result {
case .success(let value):
KVNProgress.dismiss(completion: {
block?(true, value as! Dictionary<String, Any>)
})
// BasicFunctions.displayAlert("Success", needDismiss: false, title: "Task Created Successfully")
case .failure(let responseError):
KVNProgress.dismiss(completion: {
if (responseError != nil) {
BasicFunctions.displayAlert(SERVER_ERROR)
// let json = JSONSerialization
// block!(false,responseError as! Dictionary<String, Any>)
}else{
BasicFunctions.displayAlert(SERVER_ERROR)
}
})
}
}
}
注意:确保在 Paypal 的应用设置中您已允许访问电子邮件或其他用户信息
免责声明:该项目仅适用于 POC,因此我不确定我们是否通过从客户端访问服务器端 API 违反了 PCI 合规性
【讨论】: