<commit_before># STPayment

STPayment is a utility library for writing payment forms in iOS apps.

Just add STPaymentView to your application, and it'll take care accepting card numbers, expiry, cvc and zip.

Alternatively, we've provided a bunch of classes that you can use yourself to add formatting, validation and restricting input of `UITextField`s.

In short, STPayment should greatly simplify your life when dealing with iOS payments.

![STPaymentView](http://stripe.github.com/STPayment/screenshot.png)

*For purchases related to the app, such as premium features, Apple's TOS require that you use their native In-App Purchase API. STPayments is only for purchasing products or services outside the app.*

## Installation

### Install with CocoaPods

[CocoaPods](http://cocoapods.org/) is a library dependency management tool for Objective-C. To use the Stripe iOS bindings with CocoaPods, simply add the following to your Podfile and run pod install:

    pod `STPayment`, :git => 'https://github.com/stripe/STPayment.git'

### Install by adding files to project

1. Clone this repository
1. In the menubar, click on 'File' then 'Add files to "Project"...'
1. Select the 'Stripe' directory in your cloned stripe-ios repository
1. Make sure "Copy items into destination group's folder (if needed)" is checked"
1. Click "Add"

## STPaymentView

**1)** Create a new `ViewController`, for example `PaymentViewController`.

    #import <UIKit/UIKit.h>
    #import "STPaymentView.h"

    @interface PaymentViewController : UIViewController <STPaymentViewDelegate>
    @property IBOutlet STPaymentView* paymentView;
    @end

Notice we're importing `STPaymentView.h`, the class conforms to `STPaymentViewDelegate`, and lastly we have a `paymentView` property.

**2)** Instantiate and add `STPaymentView`. We recommend you use the same frame.

    - (void)viewDidLoad
    {
    [super viewDidLoad];

    self.paymentView = [[STPaymentView alloc] initWithFrame:CGRectMake(15, 25, 290, 55)];
    self.paymentView.delegate = self;
    [self.view addSubview:self.paymentView];
    }

**3)** Implement `STPaymentViewDelegate` method `card:isValid:`. This gets passed a `STCard` instance, and a `BOOL` indicating whether the card is valid. You can enable or disable a navigational button depending on the value of `valid`, for example.

    - (void) card:(STCard *)card isValid:(BOOL)valid
    {
    NSLog(@"Card number: %@", card.number);
    NSLog(@"Card expiry: %lu/%lu", (unsigned long)card.expMonth, (unsigned long)card.expYear);
    NSLog(@"Card cvc: %@", card.cvc);
    NSLog(@"Address zip: %@", card.addressZip);

    // self.navigationItem.rightBarButtonItem.enabled = valid;
    }

That's all! No further reading is required, unless you want more flexibility by using the raw API. For more, please see the included example.

----------

# Full API

## API Example

    // Format a card number
    [[STCardNumber cardNumberWithString:@"4242424242424242"] formattedString]; //=> '4242 4242 4242 4242'
    [[STCardNumber cardNumberWithString:@"4242424242"] formattedString]; //=> '4242 4242 42'

    // Amex support
    [[STCardNumber cardNumberWithString:@"378282246310005"] formattedString]; //=> '3782 822463 10005'
    [[STCardNumber cardNumberWithString:@"378282246310005"] cardType] == STCardTypeAmex; //=> YES
<commit_msg>fix formatting<commit_after># STPayment

STPayment is a utility library for writing payment forms in iOS apps.

Just add STPaymentView to your application, and it'll take care accepting card numbers, expiry, cvc and zip.

Alternatively, we've provided a bunch of classes that you can use yourself to add formatting, validation and restricting input of `UITextField`s.

In short, STPayment should greatly simplify your life when dealing with iOS payments.

![STPaymentView](http://stripe.github.com/STPayment/screenshot.png)

*For purchases related to the app, such as premium features, Apple's TOS require that you use their native In-App Purchase API. STPayments is only for purchasing products or services outside the app.*

## Installation

### Install with CocoaPods

[CocoaPods](http://cocoapods.org/) is a library dependency management tool for Objective-C. To use the Stripe iOS bindings with CocoaPods, simply add the following to your Podfile and run pod install:

    pod `STPayment`, :git => 'https://github.com/stripe/STPayment.git'

### Install by adding files to project

1. Clone this repository
1. In the menubar, click on 'File' then 'Add files to "Project"...'
1. Select the 'Stripe' directory in your cloned stripe-ios repository
1. Make sure "Copy items into destination group's folder (if needed)" is checked"
1. Click "Add"

## STPaymentView

**1)** Create a new `ViewController`, for example `PaymentViewController`.

    #import <UIKit/UIKit.h>
    #import "STPaymentView.h"

    @interface PaymentViewController : UIViewController <STPaymentViewDelegate>
    @property IBOutlet STPaymentView* paymentView;
    @end

Notice we're importing `STPaymentView.h`, the class conforms to `STPaymentViewDelegate`, and lastly we have a `paymentView` property.

**2)** Instantiate and add `STPaymentView`. We recommend you use the same frame.

    - (void)viewDidLoad
    {
        [super viewDidLoad];

        self.paymentView = [[STPaymentView alloc] initWithFrame:CGRectMake(15, 25, 290, 55)];
        self.paymentView.delegate = self;
        [self.view addSubview:self.paymentView];
    }

**3)** Implement `STPaymentViewDelegate` method `card:isValid:`. This gets passed a `STCard` instance, and a `BOOL` indicating whether the card is valid. You can enable or disable a navigational button depending on the value of `valid`, for example.

    - (void) card:(STCard *)card isValid:(BOOL)valid
    {
        NSLog(@"Card number: %@", card.number);
        NSLog(@"Card expiry: %lu/%lu", (unsigned long)card.expMonth, (unsigned long)card.expYear);
        NSLog(@"Card cvc: %@", card.cvc);
        NSLog(@"Address zip: %@", card.addressZip);

        // self.navigationItem.rightBarButtonItem.enabled = valid;
    }

That's all! No further reading is required, unless you want more flexibility by using the raw API. For more, please see the included example.

----------

# Full API

## API Example

    // Format a card number
    [[STCardNumber cardNumberWithString:@"4242424242424242"] formattedString]; //=> '4242 4242 4242 4242'
    [[STCardNumber cardNumberWithString:@"4242424242"] formattedString]; //=> '4242 4242 42'

    // Amex support
    [[STCardNumber cardNumberWithString:@"378282246310005"] formattedString]; //=> '3782 822463 10005'
    [[STCardNumber cardNumberWithString:@"378282246310005"] cardType] == STCardTypeAmex; //=> YES

{'fraction_non_alphanumeric': 0.10658307210031348, 'fraction_numerical': 0.03403493058665472, 'mean_word_length': 4.275590551181103, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4751290', 'n_tokens_mistral': 2155, 'n_tokens_neox': 1875, 'n_words': 725}