/
CreateTransactionRequest.m
executable file
·124 lines (107 loc) · 3.01 KB
/
CreateTransactionRequest.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//
// CreateTransactionRequest.m
// ANMobilePaymentLib
//
// Created by Authorize.Net on 8/17/10.
// Copyright 2010 Authorize.Net. All rights reserved.
//
#import "CreateTransactionRequest.h"
@interface CreateTransactionRequest (private)
+ (NSString *) getTransactionTypeString:(AUTHNET_ACTION) action;
- (NSString *) stringOfXMLTransactionSettings;
- (NSString *) stringOfXMLUserFields;
@end
@implementation CreateTransactionRequest
@synthesize transactionRequest;
@synthesize transactionType;
+ (CreateTransactionRequest *) createTransactionRequest {
CreateTransactionRequest *request = [[CreateTransactionRequest alloc] init];
return request;
}
- (id) init {
self = [super init];
if (self) {
self.transactionRequest = [TransactionRequestType transactionRequest];
self.transactionType = ACTION_UNKNOWN;
}
return self;
}
- (BOOL) isValid {
// if (self.customerIPAddress != nil && self.customerIPAddress.length > MAX_CUSTOMER_IP_LENGTH) {
// return NO;
// }
//
// if (self.billingAddress != nil && ![self.billingAddress isValid]) {
// return NO;
// }
//
// if (self.creditCard != nil && ![self.creditCard isValid]) {
// return NO;
// }
//
// if (self.customer != nil && ![self.customer isValid]) {
// return NO;
// }
//
// if (self.bankAccount != nil && ![self.bankAccount isValid]) {
// return NO;
// }
//
// if (self.emailReceipt != nil && ![self.emailReceipt isValid]) {
// return NO;
// }
//
// if (self.order != nil && ![self.order isValid]) {
// return NO;
// }
//
// if (self.shippingAddress != nil && ![self.shippingAddress isValid]) {
// return NO;
// }
//
// if (self.shippingCharges != nil && ![self.shippingCharges isValid]) {
// return NO;
// }
return YES;
}
- (NSString *) stringOfXMLRequest {
NSString *s = [NSString stringWithFormat:@""
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
@"<createTransactionRequest xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\">"
@"%@" //anetApiRequest
@"%@" //transactionRequest
@"</createTransactionRequest>",
[super.anetApiRequest stringOfXMLRequest],
[self.transactionRequest stringOfXMLRequest]];
NSLog(@"Create Transaction Request: %@", s);
return s;
}
+ (NSString *) getTransactionTypeString:(AUTHNET_ACTION) action {
switch (action) {
case AUTH_ONLY:
return @"authOnlyTransaction";
break;
case AUTH_CAPTURE:
return @"authCaptureTransaction";
break;
case PRIOR_AUTH_CAPTURE:
return @"priorAuthCaptureTransaction";
break;
case CAPTURE_ONLY:
return @"captureOnlyTransaction";
break;
case VOID:
return @"voidTransaction";
break;
case CREDIT:
return @"refundTransaction";
break;
case UNLINKED_CREDIT:
return @"refundTransaction"; //Unlinked Credit is still CREDIT but no associated transaction_id.
break;
default:
return @"";
break;
}
}
@end