iOS SDK (Swift)¶
iOS SDK sizga har qanday iOS ilovangizda Visa/MasterCard/Humo/Uzcard kartalari.
iOS SDK ning eng so'nggi versiyasini har doim bizning ommaviy omborimizda topishingiz mumkin.
https://github.com/flittpayments/ios-sdk
Namuna ilovasini ishga tushirish uchun quyidagi buyruqni ijro eting
git clone git@github.com:flittpayments/ios-sdk.git
cd ios-sdk/Example
pod install
iOS SDK shuningdek CocoaPods orqali ham mavjud. Uni o'rnatish uchun Podfile'ingizga quyidagi satrni qo'shing:
pod 'Flitt'
Swift uchun misolni https://github.com/flittpayments/ios-sdk/tree/master/ExampleSwift manzilida topishingiz mumkin.
- Serverda to'lovni boshlang va to'lov tokenini oling
Serveringizda buyurtma yarating:
curl -i -X POST \
-H "Content-Type:application/json" \
-d \
'{
"request": {
"server_callback_url": "http://myshop/callback/",
"order_id": "TestOrder_JSSDK_v2",
"currency": "UZS",
"merchant_id": 4056281,
"order_desc": "Test payment",
"lifetime" : 999999,
"amount": 1000,
"signature": "91ea7da493a8367410fe3d7f877fb5e0ed666490"
}
}' \
'https://pay.payme.uz/api/checkout/token'
To'lov tokenini olish:
{
"response":{
"response_status":"success",
"token":"b3c178ad84446ef36eaab365b1e12e6987e9b3d9"
}
}
2 Xususiyatlarni aniqlash
PSCardInputView Bu foydalanuvchi tomonidan kiritilgan karta ma'lumotlarini xavfsiz qayta ishlash uchun zarur. Ilova PCI DSS talablari bo'yicha karta ma'lumotlarini saqlab ololmaydi.
PSCloudipspWKWebView 3D Secure autentifikatsiya jarayonida to'lovchini veb-ko'rinishga yo'naltirish talab etiladi.
PSCloudipspApi to'lovni boshlash uchun asosiy sinfdir.
@property (nonatomic, weak) IBOutlet PSCardInputView *cardInputView;
@property (nonatomic, strong) PSCloudipspWKWebView *webView;
@property (nonatomic, strong) PSCloudipspApi *api;
3 Karta ma'lumotlarini kiritish uchun tartiblarni yaratish
// LAYOUT FIELDS
self.cardNumberTextField = [[PSCardNumberTextField alloc] initWithFrame:CGRectMake(20, 8, 280, 30)];
self.cardNumberTextField.placeholder = @"Card Number";
[self.fields addObject:self.cardNumberTextField];
self.expMonthTextField = [[PSExpMonthTextField alloc] initWithFrame:CGRectMake(20, 46, 136, 30)];
self.expMonthTextField.placeholder = @"MM";
[self.fields addObject:self.expMonthTextField];
self.expYearTextField = [[PSExpYearTextField alloc] initWithFrame:CGRectMake(164, 46, 136, 30)];
self.expYearTextField.placeholder = @"YY";
[self.fields addObject:self.expYearTextField];
self.cvvTextField = [[PSCVVTextField alloc] initWithFrame:CGRectMake(20, 84, 280, 30)];
self.cvvTextField.placeholder = @"CVV";
[self.fields addObject:self.cvvTextField];
self.cardInputLayout = [[PSCardInputLayout alloc] initWithFrame:CGRectMake(0, 216, 320, 122)
cardNumberTextField:self.cardNumberTextField
expMonthTextField:self.expMonthTextField
expYearTextField:self.expYearTextField
cvvTextField:self.cvvTextField];
[self.scrollView addSubview:self.cardInputLayout];
4 To'lov tugmasining maketini yarating
// PAY CONTROL
self.payButton = [[UIButton alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(self.cardInputLayout.frame), 280, 30)];
[self.payButton setTitle:@"Pay" forState:UIControlStateNormal];
[self.payButton setBackgroundColor:[UIColor colorWithRed:255.f/255.f green:204.f/255.f blue:102.f/255.f alpha:1.0]];
self.payButton.layer.cornerRadius = 5.f;
[self.payButton addTarget:self action:@selector(pay:) forControlEvents:UIControlEventTouchUpInside];
[self.scrollView addSubview:self.payButton];
5 3D Secure veb-ko'rinishini sozlash
# pragma mark - Setup WebView
- (void)setupWebView {
self.webView = [[PSCloudipspWKWebView alloc] initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height - 66)];
[self.view insertSubview:self.webView aboveSubview:self.scrollView];
}
6 PSCloudipspApi obyektini ishga tushiring
self.api = [PSCloudipspApi apiWithMerchant:1396424 andCloudipspView:self.webView];
1396424 o'rniga olingan MerchantIDingizni kiritishingiz kerak.
7 'To'lash' tugmasi bosilganda, 1-qadamda olingan to'lov tokenidan foydalanib to'lovni amalga oshiring
- (IBAction)pay:(UIButton *)sender {
PSCard *card = [self.cardInputLayout confirm:self];
if (card != nil) {
[self taskWillStarted];
[self.api pay:card withToken:token andDelegate:self];
}
}
8 PSReceipt ob'ektidan to'lov natijasini qayta ishlash
# pragma mark - PayCallbackDelegate
- (void)onPaidProcess:(PSReceipt *)receipt {
self.result = [NSString stringWithFormat:NSLocalizedString(@"PAID_STATUS_KEY", nil), [PSReceipt getStatusName:receipt.status], (long)receipt.paymentId];
[self taskDidFinished];
[self navigate];
//for getting all response fields
//[PSReceiptUtils dumpFields:receipt];
}
- (void)onPaidFailure:(NSError *)error {
if ([error code] == PSPayErrorCodeFailure) {
NSDictionary *info = [error userInfo];
self.result = [NSString stringWithFormat:@"PayError. Code %@\nDescription: %@", [info valueForKey:@"error_code"], [info valueForKey:@"error_message"]];
} else {
self.result = [NSString stringWithFormat:@"Error: %@", [error localizedDescription]];
}
[self navigate];
[self taskDidFinished];
}