Skip to content

Commit

Permalink
introduce style defaults with clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-stripe committed Oct 22, 2014
1 parent 45cb00e commit 2bac4fc
Show file tree
Hide file tree
Showing 20 changed files with 486 additions and 411 deletions.
58 changes: 58 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
ConstructorInitializerIndentWidth: 4
AlignEscapedNewlinesLeft: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AlwaysBreakTemplateDeclarations: false
AlwaysBreakBeforeMultilineStrings: false
BreakBeforeBinaryOperators: false
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: false
BinPackParameters: false
BinPackParameters: false
ColumnLimit: 160
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: true
DisableFormat: false
ExperimentalAutoDetectBinPacking: true
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
IndentFunctionDeclarationAfterType: false
MaxEmptyLinesToKeep: 1
KeepEmptyLinesAtTheStartOfBlocks: false
NamespaceIndentation: None
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: false
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakString: 1000
PenaltyBreakFirstLessLess: 120
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpacesInAngles: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpaceInEmptyParentheses: false
SpacesInParentheses: false
SpacesBeforeTrailingComments: 1
Standard: Cpp11
TabWidth: 8
UseTab: Never
...

58 changes: 58 additions & 0 deletions Example/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
ConstructorInitializerIndentWidth: 4
AlignEscapedNewlinesLeft: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AlwaysBreakTemplateDeclarations: false
AlwaysBreakBeforeMultilineStrings: false
BreakBeforeBinaryOperators: false
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: false
BinPackParameters: false
BinPackParameters: false
ColumnLimit: 160
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: true
DisableFormat: false
ExperimentalAutoDetectBinPacking: true
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
IndentFunctionDeclarationAfterType: false
MaxEmptyLinesToKeep: 1
KeepEmptyLinesAtTheStartOfBlocks: false
NamespaceIndentation: None
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: false
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakString: 1000
PenaltyBreakFirstLessLess: 120
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpacesInAngles: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpaceInEmptyParentheses: false
SpacesInParentheses: false
SpacesBeforeTrailingComments: 1
Standard: Cpp11
TabWidth: 8
UseTab: Never
...

2 changes: 1 addition & 1 deletion Example/StripeExample/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>
@interface AppDelegate : UIResponder<UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

Expand Down
6 changes: 2 additions & 4 deletions Example/StripeExample/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if (StripePublishableKey) {
[Stripe setDefaultPublishableKey:StripePublishableKey];
}
if (ParseApplicationId && ParseClientKey) {
[Parse setApplicationId:ParseApplicationId
clientKey:ParseClientKey];
[Parse setApplicationId:ParseApplicationId clientKey:ParseClientKey];
}
return YES;
}
Expand Down
6 changes: 3 additions & 3 deletions Example/StripeExample/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

#import <Foundation/Foundation.h>

extern NSString * const StripePublishableKey;
extern NSString * const ParseApplicationId;
extern NSString * const ParseClientKey;
extern NSString *const StripePublishableKey;
extern NSString *const ParseApplicationId;
extern NSString *const ParseClientKey;

@interface Constants : NSObject

Expand Down
6 changes: 3 additions & 3 deletions Example/StripeExample/Constants.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
#warning Replace these with your own values and then remove this warning. Make sure to replace the values in StripeExample/Parse/config/global.json as well if you want to use Parse.

// This can be found at https://dashboard.stripe.com/account/apikeys
NSString * const StripePublishableKey = @"pk_YT1CEhhujd0bklb2KGQZiaL3iTzj3"; // TODO: replace nil with your own value
NSString *const StripePublishableKey = @"pk_YT1CEhhujd0bklb2KGQZiaL3iTzj3"; // TODO: replace nil with your own value

// These can be found at https://www.parse.com/apps/stripe-test/edit#app_keys
NSString * const ParseApplicationId = nil; // TODO: replace nil with your own value
NSString * const ParseClientKey = nil; // TODO: replace nil with your own value
NSString *const ParseApplicationId = nil; // TODO: replace nil with your own value
NSString *const ParseClientKey = nil; // TODO: replace nil with your own value

@implementation Constants
@end
2 changes: 1 addition & 1 deletion Example/StripeExample/PaymentViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@interface PaymentViewController : UIViewController

@property(nonatomic)NSDecimalNumber *amount;
@property (nonatomic) NSDecimalNumber *amount;
- (IBAction)save:(id)sender;

@end
91 changes: 50 additions & 41 deletions Example/StripeExample/PaymentViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#import <Parse/Parse.h>
#import "Constants.h"

@interface PaymentViewController ()<PTKViewDelegate>
@property(weak, nonatomic) PTKView *paymentView;
@interface PaymentViewController () <PTKViewDelegate>
@property (weak, nonatomic) PTKView *paymentView;
@end

@implementation PaymentViewController
Expand All @@ -23,27 +23,25 @@ - (void)viewDidLoad {
self.view.backgroundColor = [UIColor whiteColor];
self.title = @"Checkout";
if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
self.edgesForExtendedLayout = UIRectEdgeNone;
self.edgesForExtendedLayout = UIRectEdgeNone;
}

// Setup save button
NSString *title = [NSString stringWithFormat:@"Pay $%@", self.amount];
UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:title style:UIBarButtonItemStyleDone target:self action:@selector(save:)];
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancel:)];
saveButton.enabled = NO;
self.navigationItem.leftBarButtonItem = cancelButton;
self.navigationItem.rightBarButtonItem = saveButton;

// Setup checkout
PTKView *paymentView = [[PTKView alloc] initWithFrame:CGRectMake(15, 20, 290, 55)];
paymentView.delegate = self;
self.paymentView = paymentView;
[self.view addSubview:paymentView];
}

- (void)paymentView:(PTKView *)paymentView
withCard:(PTKCard *)card
isValid:(BOOL)valid {
- (void)paymentView:(PTKView *)paymentView withCard:(PTKCard *)card isValid:(BOOL)valid {
// Enable save button if the Checkout is valid
self.navigationItem.rightBarButtonItem.enabled = valid;
}
Expand Down Expand Up @@ -71,14 +69,15 @@ - (IBAction)save:(id)sender {
card.expMonth = self.paymentView.card.expMonth;
card.expYear = self.paymentView.card.expYear;
card.cvc = self.paymentView.card.cvc;
[Stripe createTokenWithCard:card completion:^(STPToken *token, NSError *error) {
[MBProgressHUD hideHUDForView:self.view animated:YES];
if (error) {
[self hasError:error];
} else {
[self hasToken:token];
}
}];
[Stripe createTokenWithCard:card
completion:^(STPToken *token, NSError *error) {
[MBProgressHUD hideHUDForView:self.view animated:YES];
if (error) {
[self hasError:error];
} else {
[self hasToken:token];
}
}];
}

- (void)hasError:(NSError *)error {
Expand All @@ -90,40 +89,50 @@ - (void)hasError:(NSError *)error {
[message show];
}

- (void)hasToken:(STPToken *)token
{
- (void)hasToken:(STPToken *)token {
[MBProgressHUD showHUDAddedTo:self.view animated:YES];

NSDictionary *chargeParams = @{
@"token": token.tokenId,
@"currency": @"usd",
@"amount": @"1000", // this is in cents (i.e. $10)
};
@"token": token.tokenId,
@"currency": @"usd",
@"amount": @"1000", // this is in cents (i.e. $10)
};

if (!ParseApplicationId || !ParseClientKey) {
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Todo: Submit this token to your backend"
message:[NSString stringWithFormat:@"Good news! Stripe turned your credit card into a token: %@ \nYou can follow the instructions in the README to set up Parse as an example backend, or use this token to manually create charges at dashboard.stripe.com .", token.tokenId]
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK", @"OK")
otherButtonTitles:nil];

UIAlertView *message =
[[UIAlertView alloc] initWithTitle:@"Todo: Submit this token to your backend"
message:[NSString stringWithFormat:@"Good news! Stripe turned your credit card into a token: %@ \nYou can follow the "
@"instructions in the README to set up Parse as an example backend, or use this "
@"token to manually create charges at dashboard.stripe.com .",
token.tokenId]
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK", @"OK")
otherButtonTitles:nil];

[message show];
[MBProgressHUD hideHUDForView:self.view animated:YES];
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
return;
}

// This passes the token off to our payment backend, which will then actually complete charging the card using your account's
[PFCloud callFunctionInBackground:@"charge" withParameters:chargeParams block:^(id object, NSError *error) {
[MBProgressHUD hideHUDForView:self.view animated:YES];
if (error) {
[self hasError:error];
return;
}
[self.presentingViewController dismissViewControllerAnimated:YES completion:^{
[[[UIAlertView alloc] initWithTitle:@"Payment Succeeded" message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil] show];
}];
}];
[PFCloud callFunctionInBackground:@"charge"
withParameters:chargeParams
block:^(id object, NSError *error) {
[MBProgressHUD hideHUDForView:self.view animated:YES];
if (error) {
[self hasError:error];
return;
}
[self.presentingViewController dismissViewControllerAnimated:YES
completion:^{
[[[UIAlertView alloc] initWithTitle:@"Payment Succeeded"
message:nil
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:@"OK", nil] show];
}];
}];
}

@end
Loading

0 comments on commit 2bac4fc

Please sign in to comment.