BucketSDK
示例
要运行示例工程,请先克隆仓库,然后从 Example 目录运行 pod install
要求
您需要在 Bucket 上注册,并获得零售商账户。为了访问 Bucket 的 API,您需要收到 clientId 和 clientSecret。
安装
BucketSDK 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile:
pod 'BucketSDK'
用法
使用 BucketSDK,您将能够使用 Swift 或 Objective-C 访问您所需要的某些功能。
Swift 使用
// Check your app's status of being in release or debug. This will make it easier for you as the developer to always make sure you are hitting the Sandbox API rather than the Production API. We suggest doing this in the App Delegate launch options.
#if RELEASE
Bucket.shared.environment = .Production
#endif
// Okay now that you set the environment, you should be able to log in with a Retailer:
Bucket.Retailer.logInWith(password: "password", username: "username") { (success, error) in
if success {
// Yay - we successfully logged in!
} else if let error = error {
print(error.localizedDescription)
}
}
// Now before using the Bucket.shared.bucketAmount(for: entireChangeAmountWithBills), you will need to set your bill denomination:
Bucket.shared.fetchBillDenominations(.usd) { (success, error) in
if success {
} else if error != nil {
}
}
// Another function you will use will be to calculate how much we are bucketing based on the dollar bills and change given. Notice that we deal with the currency as an integer:
let bucketAmount = Bucket.shared.bucketAmount(for: 7899)
// Now that we have our bucket amount, we can go and create a transaction with that amount, and send it through the Bucket API:
let transaction = Bucket.Transaction(amount: bucketAmount, clientTransactionId: "CKFYGGHPUIGH")
transaction.create { (success, error) in
if success {
// Yay we created the transaction!
} else if let error = error {
print(error.localizedDescription)
}
}
// You will need to close the interval for the start-to-end of day.
// Close an interval:
Bucket.shared.close(interval: "20180422")
// OR use the callback:
Bucket.shared.close(interval: "20180422") { (success, error) in
if success {
// Success!!
}
else if !error.isNil {
print(error!.localizedDescription)
}
}
Obj-C 使用
// Check your app's status of being in release or debug. This will make it easier for you as the developer to always make sure you are hitting the Sandbox API rather than the Production API. We suggest doing this in the App Delegate launch options.
#if RELEASE
[Bucket.shared setEnvironment: DeploymentEnvironmentProduction];
#endif
// Okay now that you set the environment, you should be able to log in with a Retailer:
[Retailer logInWithPassword:@"password" username:@"username" :^(BOOL success, NSError * _Nullable error) {
if (success) {
// Yay - it was a success!!
} else if (error != NULL) {
NSLog(@"%@", error.localizedDescription);
}
}];
// Before using the function bucketAmountFor, you will need to set your bill denominations:
[[Bucket shared] fetchBillDenominations:BillDenominationUsd completion:^(BOOL success, NSError * _Nullable error) {
if (success) {
long bucketAmount = [[Bucket shared] bucketAmountFor:863];
NSLog(@"Success!!!: %li", bucketAmount);
} else if (error != NULL) {
}
}];
// Another function you will use will be to calculate how much we are bucketing based on the dollar bills and change given. Notice that we deal with the currency as an integer:
long bucketAmount = [[Bucket shared] bucketAmountFor:7999];
// Now that we have our bucket amount, we can go and create a transaction with that amount, and send it through the Bucket API:
Transaction *t = [[Transaction alloc] initWithAmount:bucketAmount clientTransactionId:@"ZDFRPHGYKOUG"];
[t create:^(BOOL success, NSError * _Nullable error) {
if (success) {
// You successfully created the transaction!
} else if (error != NULL) {
NSLog(@"%@", error.localizedDescription);
}
}];
// You will need to close the interval for the start-to-end of day.
// No completion:
[Bucket.shared closeWithInterval:@"20180423" : NULL];
// With completion:
[Bucket.shared closeWithInterval:@"20180423" :^(BOOL success, NSError * _Nullable error) {
if (success) {
// Success!!!!
} else if (error != NULL) {
NSLog(@"%@",error.localizedDescription);
}
}];
作者
Ryan, [email protected]
许可协议
BucketSDK 在 MIT 许可协议下可用。有关更多信息,请参阅 LICENSE 文件。