1. //
  2. // CompraDatosPago_ViewController.m
  3. // Cinépolis
  4. //
  5. // Created by jgaona on 22/07/13.
  6. // Copyright (c) 2013 IA Interactive. All rights reserved.
  7. //
  8. #import "CompraDatosPago_ViewController.h"
  9. #import "AppDelegate.h"
  10. #import "Compra_ViewController.h"
  11. #import "AppDelegate.h"
  12. #import "CompraConfirmacion_ViewController.h"
  13. #import "Global.h"
  14. #import "TarjetaBancaria.h"
  15. #import "Datos.h"
  16. #import "TSMessage.h"
  17. #import "LocalizationSystem.h"
  18. #import "Cinecash.h"
  19. #import "CargandoCinepolis.h"
  20. #import "UIFont+CustomInit.h"
  21. #import "InstructionsView.h"
  22. #import "UIAlertView+Blocks.h"
  23. #import "Cartelera_ViewController.h"
  24. #import "CarteleraIPhonePlus_ViewController.h"
  25. #import "UIViewController+IniciaConEstilo.h"
  26. #import <TrustDefenderMobile/TrustDefenderMobile.h>
  27. ============
  28. @interface CompraDatosPago_ViewController ()
  29. {
  30. UIButton *btn_visa;
  31. BOOL usando_visa;
  32. }
  33. @property (strong, nonatomic) VisaCheckout *visaCheckout;
  34. @end
  35. ============
  36. btn_visa = [[UIButton alloc] initWithFrame:self.btn_adelante.frame];
  37. btn_visa.hidden = YES;
  38. [btn_visa setBackgroundImage:[UIImage imageNamed:@"visa_checkout_btn"] forState:UIControlStateNormal];
  39. [btn_visa addTarget:self action:@selector(invokeVISASDKDirectly) forControlEvents:UIControlEventTouchDown];
  40. [self.btn_adelante.superview addSubview:btn_visa];
  41. ============
  42. #pragma mark - Visa Invoke
  43. - (void)invokeVISASDKDirectly {
  44. [self.visaCheckout invokeVisaCheckout:^(NSError *error) {
  45. if (error) {
  46. NSLog(@"Error Details..%@", [error localizedDescription]);
  47. }
  48. } withOptions:nil withDelegate:self];
  49. }
  50. #pragma mark - Visa Checkout delegate
  51. - (void)checkoutSuccessWithSummary:(VisaPaymentSummary*)paymentSummary {
  52. NSLog(@"success");
  53. NSString *successResponse = [NSString stringWithFormat:@"callID: %@\r lastFourDigits: %@\r cardBrand: %@\r cardType: %@\r countryCode: %@\r postalCode: %@\r encKey: %@\r encPaymentData: %@",paymentSummary.callId,
  54. paymentSummary.lastFourDigits, paymentSummary.cardBrand, paymentSummary.cardType, paymentSummary.countryCode, paymentSummary.postalCode, paymentSummary.encKey, paymentSummary.encPaymentData];
  55. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Payment successful!" message:successResponse delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
  56. [alertView show];
  57. }
  58. - (void)checkoutFailedWithError:(NSError*)error{
  59. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:[error localizedDescription] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
  60. [alertView show];
  61. NSLog(@"Error - %@", [error description]);
  62. }
  63. - (void)checkoutCancelled {
  64. NSLog(@"Cancelled");
  65. }
  66. ============
  67. - (VisaPaymentInfo *)paymentInfo {
  68. VisaPaymentInfo *paymentInfo = [[VisaPaymentInfo alloc] init];
  69. [paymentInfo setAmount:[NSDecimalNumber decimalNumberWithString:@"12"]];
  70. [paymentInfo setCurrency:VCurrencyCodeUS];
  71. paymentInfo.merchantRequestId = @"a001";
  72. paymentInfo.subtotal = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%f", [[Global sharedInstance].compra TotalCantidadEnCentavos:YES]]];
  73. paymentInfo.shippingHandlingCharges = [NSDecimalNumber decimalNumberWithString:@"0"];
  74. paymentInfo.tax = [NSDecimalNumber decimalNumberWithString:@"0"];
  75. paymentInfo.discount = [NSDecimalNumber decimalNumberWithString:@"0"];
  76. paymentInfo.giftWrapCharges = [NSDecimalNumber decimalNumberWithString:@"0"];
  77. paymentInfo.miscCharges = [NSDecimalNumber decimalNumberWithString:@"0"];
  78. paymentInfo.paymentDescription = @"tickets";
  79. paymentInfo.orderId = @"111";
  80. paymentInfo.promoCode = @"freeCheckout";
  81. paymentInfo.isShippingAddressRequired = YES;
  82. paymentInfo.datalevel = @"SUMMARY";
  83. // Pass merchant informationu
  84. VisaMerchantInfo *merchantInfo = [[VisaMerchantInfo alloc] init];
  85. merchantInfo.merchantAPIKey = @"LXFQZOKJIXXFYO20OMI313Hal2ScbAZYETLKqaXZpHFqZ8bDw";
  86. merchantInfo.userReviewAction = kVisaUserReviewActionContinue;
  87. merchantInfo.displayName = @"Cinépolis";
  88. merchantInfo.externalProfileId = @"defaultprofile";
  89. merchantInfo.merchantLogoAssetName = @"mercLogo";
  90. merchantInfo.canadianDebitCardSupport = VAcceptCanadianDebitCard;
  91. merchantInfo.preferredLocale = VLocale_enUS;
  92. paymentInfo.merchantInfo = merchantInfo;
  93. //set up 3DS
  94. VisaThreeDSSetUp *threeDSSetUp = [VisaThreeDSSetUp new];
  95. threeDSSetUp.threeDSActive = VisaActivate3DS;
  96. paymentInfo.threeDSSetUp = threeDSSetUp;
  97. NSMutableArray *cardBrandArray = [[NSMutableArray alloc] initWithObjects:@"Visa", @"MasterCard", @"AMEX", @"Discover", nil];
  98. paymentInfo.acceptedPaymentTypesAndBrands = cardBrandArray;
  99. //set accepted countries for shipping
  100. NSMutableArray *acceptedShippingCountryList = [[NSMutableArray alloc] initWithObjects:@"MX", nil];
  101. paymentInfo.acceptedShippingCountries = acceptedShippingCountryList;
  102. //set accepted countries for billing
  103. NSMutableArray *acceptedBillingCountryList = [[NSMutableArray alloc] initWithObjects:@"MX", nil];
  104. paymentInfo.acceptedBillingCountries = acceptedBillingCountryList;
  105. return paymentInfo;
  106. }