Created
April 25, 2012 04:47
-
-
Save tdelam/2486469 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void) loginToGateway { | |
MobileDeviceLoginRequest *mobileDeviceLoginRequest = | |
[MobileDeviceLoginRequest mobileDeviceLoginRequest]; | |
mobileDeviceLoginRequest.anetApiRequest.merchantAuthentication.name = <USERNAME>; | |
mobileDeviceLoginRequest.anetApiRequest.merchantAuthentication.password = <PASSWORD>; | |
mobileDeviceLoginRequest.anetApiRequest.merchantAuthentication.mobileDeviceId = | |
[[[UIDevice currentDevice] uniqueIdentifier] | |
stringByReplacingOccurrencesOfString:@"-" withString:@"_"]; | |
AuthNet *an = [AuthNet getInstance]; | |
[an setDelegate:self]; | |
[an mobileDeviceLoginRequest: mobileDeviceLoginRequest]; | |
} | |
- (void) createTransaction { | |
AuthNet *an = [AuthNet getInstance]; | |
[an setDelegate:self]; | |
CreditCardType *creditCardType = [CreditCardType creditCardType]; | |
creditCardType.cardNumber = @"4111111111111111"; | |
creditCardType.cardCode = @"100"; | |
creditCardType.expirationDate = @"1212"; | |
PaymentType *paymentType = [PaymentType paymentType]; | |
paymentType.creditCard = creditCardType; | |
ExtendedAmountType *extendedAmountTypeTax = [ExtendedAmountType extendedAmountType]; | |
extendedAmountTypeTax.amount = @"0"; | |
extendedAmountTypeTax.name = @"Tax"; | |
ExtendedAmountType *extendedAmountTypeShipping = [ExtendedAmountType extendedAmountType]; | |
extendedAmountTypeShipping.amount = @"0"; | |
extendedAmountTypeShipping.name = @"Shipping"; | |
LineItemType *lineItem = [LineItemType lineItem]; | |
lineItem.itemName = @"Soda"; | |
lineItem.itemDescription = @"Soda"; | |
lineItem.itemQuantity = @"1"; | |
lineItem.itemPrice = @"1.00"; | |
lineItem.itemID = @"1"; | |
TransactionRequestType *requestType = [TransactionRequestType transactionRequest]; | |
requestType.lineItems = [NSArray arrayWithObject:lineItem]; | |
requestType.amount = @"1.00"; | |
requestType.payment = paymentType; | |
requestType.tax = extendedAmountTypeTax; | |
requestType.shipping = extendedAmountTypeShipping; | |
CreateTransactionRequest *request = [CreateTransactionRequest createTransactionRequest]; | |
request.transactionRequest = requestType; | |
request.transactionType = AUTH_ONLY; | |
request.anetApiRequest.merchantAuthentication.mobileDeviceId = | |
[[[UIDevice currentDevice] uniqueIdentifier] | |
stringByReplacingOccurrencesOfString:@"-" withString:@"_"]; | |
request.anetApiRequest.merchantAuthentication.sessionToken = sessionToken; | |
[an purchaseWithRequest:request]; | |
} | |
- (void) requestFailed:(AuthNetResponse *)response { | |
// Handle a failed request | |
} | |
- (void) connectionFailed:(AuthNetResponse *)response { | |
// Handle a failed connection | |
} | |
- (void) paymentSucceeded:(CreateTransactionResponse *) response { | |
// Handle payment success | |
} | |
- (void) mobileDeviceLoginSucceeded:(MobileDeviceLoginResponse *)response { | |
sessionToken = [response.sessionToken retain]; | |
[self createTransaction]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment