Comments (3)
this would be useful in conjunction with https://github.com/card-io/card.io-iOS-SDK
from paymentkit.
I just wanted to fill in the card number from the number returned from card-io. Not the CVC or expiry.
I could do this separating a card number string into an array of single character NSStrings, and iterating through the array, and pasting the string up to that point into the cardNumberField
UIPasteboard *pb = [UIPasteboard generalPasteboard];
NSString *originalPasteboard = pb.string;
NSMutableArray *numberArray = [NSMutableArray array];
NSString *str = info.cardNumber;
for (int i = 0; i < [str length]; i++) {
NSString *ch = [str substringWithRange:NSMakeRange(i, 1)];
[numberArray addObject:ch];
}
[cell.paymentView.cardNumberField becomeFirstResponder];
cell.paymentView.cardNumberField.text = @"";
for (int i = 0; i < [numberArray count]; i++) {
float f = (float)i * 0.02;
NSString *number = [numberArray objectAtIndex:i];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSMutableString *newString = [cell.paymentView.cardNumberField.text mutableCopy];
[newString appendString:number];
pb.string = number;
[cell.paymentView.cardNumberField paste:self];
pb.string = @"";
if (i == (numberArray.count-1)) pb.string = originalPasteboard;
});
}
from paymentkit.
I solved this by creating a category for PTKView that provides a setCardNumber method and calls the textField:shouldChangeCharactersInRange:replacementString method like so:
PTKView+Programmable.h
@interface PTKView (Programmable)
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)replacementString;
- (void)setCardNumber:(NSString *)cardNumber;
@end
PTKView+Programmable.m
@implementation PTKView (Programmable)
- (void)setCardNumber:(NSString *)cardNumber {
NSRange range = NSMakeRange(0, [self cardNumberField].text.length);
[self textField:[self cardNumberField] shouldChangeCharactersInRange:range replacementString:cardNumber];
}
@end
Since I'm using swift, I also had to add #import "PTKView+Programmable.h"
to my Bridging-Header.h file.
Then I could simply call self.pkView.setCardNumber(cardNumber)
in my PaymentViewController.
Since there are obvious use cases for setting the card fields programmatically (such as Card.io), please add this feature natively.
from paymentkit.
Related Issues (20)
- iOS8 with Swift HOT 4
- Prefix Resources HOT 1
- PTKView is not full width on iPhone 6 and iPhone 6 Plus when running in native resolution HOT 9
- Allows months to be entered as 00 HOT 1
- PTKCardExpiry.m Deprecations HOT 1
- Fix PTKTextField.h warnings in Xcode 6.3.1 HOT 1
- Missing API Delegates? HOT 2
- WARN | PaymentKit/PaymentKit/PTKTextField.h:25:54: warning: auto property synthesis will not synthesize property 'delegate'; it will be implemented by its superclass, use @dynamic to acknowledge intention [-Wobjc-property-synthesis] HOT 1
- Better card number state handling HOT 3
- Looks Broken-ish in iOS 9 HOT 4
- deprecated date constants
- Adjust look of payment view HOT 2
- Add support for Carthage HOT 1
- CocoaPods use_frameworks! images are not shown HOT 1
- [meta] Refactor to fix UI issues HOT 1
- Invalid Card number doesn't have a red text anymore HOT 1
- No way to validate custom textFields?
- cocoapod Stripe 6.2.0 : duplicate symbols while linking HOT 1
- duplicate interface definition for class HOT 1
- Migration from stripe 4.0 to latest stripe 8.x HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from paymentkit.