简体   繁体   中英

Xamarin.iOS binding for WePay

I am creating a Xamarin binding for the WePay.iOS SDK using objective sharpie. https://github.com/wepay/wepay-ios

I have managed to build the APIDefinition.cs and StructsAndEnums.cs files. However when I created the binding project, it does not compile successfully.

[Export ("initWithSwipedInfo:")]
    IntPtr Constructor (NSObject swipedInfo);

    // -(instancetype)initWithEMVInfo:(id)emvInfo;
    [Export ("initWithEMVInfo:")]
    IntPtr Constructor (NSObject emvInfo);

I understand that I need to change the NSOBject to the correct datatype. However, when I look into the Objective C file. I cant really make sense of what datatype should I be using. I appreciate if someone can guide me in it.

Objective-C Class

@interface WPPaymentInfo : NSObject
@property (nonatomic, strong, readonly) NSString *firstName;
@property (nonatomic, strong, readonly) NSString *lastName;
@property (nonatomic, strong, readonly) NSString *email;
@property (nonatomic, strong, readonly) NSString *paymentDescription;
@property (nonatomic, readonly) BOOL isVirtualTerminal;
@property (nonatomic, strong, readonly) WPAddress *billingAddress;
@property (nonatomic, strong, readonly) WPAddress *shippingAddress;
@property (nonatomic, strong, readonly) id paymentMethod;
@property (nonatomic, strong, readonly) id swiperInfo;
@property (nonatomic, strong, readonly) id manualInfo;
@property (nonatomic, strong, readonly) id emvInfo;

- (instancetype) initWithSwipedInfo:(id)swipedInfo;
- (instancetype) initWithEMVInfo:(id)emvInfo;
- (instancetype) initWithFirstName:(NSString *)firstName
                      lastName:(NSString *)lastName
                         email:(NSString *)email
                billingAddress:(WPAddress *)billingAddress
               shippingAddress:(WPAddress *)shippingAddress
                    cardNumber:(NSString *)cardNumber
                           cvv:(NSString *)cvv
                      expMonth:(NSString *)expMonth
                       expYear:(NSString *)expYear
               virtualTerminal:(BOOL)virtualTerminal;

- (void) addEmail:(NSString *)email;
@end

swipedInfo and emvInfo are internally of type NSMutableDictionary.

See here :

- (void) handleSwipeResponse:(NSDictionary *) responseData 
{
    NSDictionary *info = @{@"firstName"         : [WPRoamHelper firstNameFromRUAData:responseData],
                           @"lastName"          : [WPRoamHelper lastNameFromRUAData:responseData],
                           @"paymentDescription": pan ? pan : @"",
                           @"swiperInfo"        : responseData
                        };

    WPPaymentInfo *paymentInfo = [[WPPaymentInfo alloc] initWithSwipedInfo:info]; 
}

@y2chaits Xamarin runs on top of Mono and it is C#. C# does not allow overload with the same signature. So, it is good to create concrete datatype instead. You did similar think when you've changed WPAddress.

In this case you can set one constructor to NSObject and the second to NSDictionary (see here: https://github.com/dikoga/WePayBinding/blob/master/WePayBinding/ApiDefinition.cs ). And you will be good.

However, this bind is already done. It is building but it has one issue ( http://forums.xamarin.com/discussion/66446/how-to-get-more-information-when-the-app-crashes ). Maybe you can put some effort to help make it works since it is already on github.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM