Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't dismiss presentPaymentMethodsViewController #882

Closed
jlubeck opened this issue Jan 11, 2018 · 3 comments
Closed

Can't dismiss presentPaymentMethodsViewController #882

jlubeck opened this issue Jan 11, 2018 · 3 comments

Comments

@jlubeck
Copy link

jlubeck commented Jan 11, 2018

To make it easier to diagnose your issue, please fill out the following:

Summary

When using [paymentContext presentPaymentMethodsViewController], everything works great when adding a new card.

But if for some reason I want to cancel, after I tap on the Cancel button, nothing happens. So I'm stuck inside that controller.

Code to reproduce

    self.customerContext = [[STPCustomerContext alloc] initWithKeyProvider:[Api sharedManager]];
    self.paymentContext = [[STPPaymentContext alloc] initWithCustomerContext:self.customerContext];
    self.paymentContext.hostViewController = self;
    self.paymentContext.delegate = self;
[self.paymentContext presentPaymentMethodsViewController];

iOS version

seen on both 10 & 11

Installation method

Cocoapods

SDK version

11.5.0

@jlubeck
Copy link
Author

jlubeck commented Jan 11, 2018

A bit more info that I found...

I noticed there is a delegate STPPaymentMethodsViewControllerDelegate that handles the cancel button tap, which sounds like the best place to dismiss the view. But when using the paymentContext:presentPaymentMethodsViewController method, I'm not finding any way to actually set that delegate.

I would image it was being made internally, but putting a break-point in the file STPPaymentMethodsViewController.m on the method internalViewControllerDidCancel I see that the delegate is in fact nil.

So, even though that method gets invoked when I tap on the cancel button, given there is no delegate assigned, it's not doing anything to actually dismiss the viewcontroller.

Hope this helps.

@danj-stripe
Copy link
Contributor

Hi @jlubeck,

When you call - [STPPaymentContext presentPaymentMethodsViewController], the STPPaymentMethodsViewController's delegate is the paymentContext doing the presenting. If you're seeing that the delegate is nil in internalViewControllerDidCancel or addCardViewControllerDidCancel:, I'd suspect that your code isn't retaining the STPPaymentContext object and it's being released, but I'm not sure.

You could also take a look through the example code to see how we're using the STPPaymentContext. CheckoutViewController.swift is a good place to start.

Finally, if you're still having trouble, you should email support@stripe.com. They're available to answer questions and help you integrate the SDK. Generally we reserve GitHub issues for bug reports.

Thanks,
Dan

@jlubeck
Copy link
Author

jlubeck commented Jan 11, 2018

Hi @danj-stripe thank you for your reply. I understand this is for bug reports. That's why I came here in the first place, because it doesn't look like I'm doing something wrong so I'm suspecting a bug.

I'm strongly retaining the paymentContext do that shouldn't be the issue.
here is the full implementation of my class btw. I'm going to write to support as well, but I'd appreciate you take a look as well. Thank you

@interface ProfileVC ()<UIPickerViewDelegate, UIPickerViewDataSource, UITextFieldDelegate,STPPaymentContextDelegate,STPPaymentMethodsViewControllerDelegate>
@property (weak, nonatomic) IBOutlet UILabel *lblHeader;
@property (weak, nonatomic) IBOutlet UITextField *txtPassword;
@property (weak, nonatomic) IBOutlet UITextField *txtPassword2;
@property (weak, nonatomic) IBOutlet UITextField *txtCountry;
@property (weak, nonatomic) IBOutlet UITextField *txtName;
@property (weak, nonatomic) IBOutlet UITextField *txtLastName;
@property (weak, nonatomic) IBOutlet UITextField *txtDni;
@property (weak, nonatomic) IBOutlet UITextField *txtEmail;
@property (weak, nonatomic) IBOutlet UITextField *txtAddress;
@property (weak, nonatomic) IBOutlet UITextField *txtPhone;
@property (weak, nonatomic) IBOutlet UIView *txtPasswordContainer;
@property (weak, nonatomic) IBOutlet UIView *txtPassword2Container;
@property (weak, nonatomic) IBOutlet UIView *txtCountryContainer;
@property (weak, nonatomic) IBOutlet UIView *txtNameContainer;
@property (weak, nonatomic) IBOutlet UIView *txtLastNameContainer;
@property (weak, nonatomic) IBOutlet UIView *txtDniContainer;
@property (weak, nonatomic) IBOutlet UIView *txtEmailContainer;
@property (weak, nonatomic) IBOutlet UIView *txtAddressContainer;
@property (weak, nonatomic) IBOutlet UIView *txtPhoneContainer;
@property (weak, nonatomic) IBOutlet UIButton *btnContinue;
@property (weak, nonatomic) IBOutlet UIStackView *stackViewCC;
@property (weak, nonatomic) IBOutlet UITextField *txtCC;
@property (weak, nonatomic) IBOutlet UIView *viewCC;
@property (weak, nonatomic) IBOutlet UIButton *btnCC;
@property (weak, nonatomic) IBOutlet UIImageView *imgCC;
@property (strong, nonatomic) UIPickerView *pickerCountry;
@property (strong, nonatomic) NSArray<CountryDTO*> *countries;

@property (strong, nonatomic) STPCustomerContext *customerContext;
@property (strong, nonatomic) STPPaymentContext *paymentContext;

@end

static void *ProductContext = &ProductContext;

@implementation ProfileVC

- (void)viewDidLoad {
    [super viewDidLoad];

    if(CurrentUser.userDto && CurrentUser.userDto.ID > 0){
        self.stackViewCC.hidden = NO;
        self.lblHeader.text = @"Tus Datos";
        [self.btnContinue setTitle:@"Guardar" forState:UIControlStateNormal];
        
        //See if there is a credit card saved
        self.customerContext = [[STPCustomerContext alloc] initWithKeyProvider:[Api sharedManager]];
        self.paymentContext = [[STPPaymentContext alloc] initWithCustomerContext:self.customerContext configuration:[STPPaymentConfiguration sharedConfiguration] theme:CurrentUser.theme];
        self.paymentContext.hostViewController = self;
        self.paymentContext.delegate = self;
    }else{
        self.stackViewCC.hidden = YES;
        self.lblHeader.text = @"Registro";
        [self.btnContinue setTitle:@"Registrar" forState:UIControlStateNormal];
    }

    self.pickerCountry = [[UIPickerView alloc] initWithFrame:CGRectZero];
    self.pickerCountry.delegate = self;
    self.pickerCountry.dataSource = self;
    self.txtCountry.inputView = self.pickerCountry;

    if(CurrentUser.userDto){
        self.txtPasswordContainer.hidden = YES;
        self.txtPassword2Container.hidden = YES;

        self.txtCountry.text = CurrentUser.userDto.country.name;
        self.txtName.text = CurrentUser.userDto.name;
        self.txtLastName.text = CurrentUser.userDto.lastName;
        self.txtDni.text = CurrentUser.userDto.dni;
        self.txtAddress.text = CurrentUser.userDto.address;
        self.txtEmail.text = CurrentUser.userDto.email;
        self.txtPhone.text = CurrentUser.userDto.phone;
    }
    
    [UserService getCountriesSuccess:^(NSArray *countries) {
        self.countries = countries;
    } failure:nil];

}

- (IBAction)onBack:(id)sender {
	[self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)onContinue:(id)sender {
        UserDTO *user = [UserDTO new];
        user.password = self.txtPassword.text;
        user.country = self.countries[[self.pickerCountry selectedRowInComponent:0]];
        user.name = self.txtName.text;
        user.lastName = self.txtLastName.text;
        user.dni = self.txtDni.text;
        user.email = self.txtEmail.text;
        user.address = self.txtAddress.text;
        user.phone = self.txtPhone.text;
        if(CurrentUser.userDto && CurrentUser.userDto.ID > 0){
            //Edit user
            MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
            hud.label.text = @"Guardando...";
            [UserService updateUser:user success:^(UserDTO *result) {
                [self.navigationController popViewControllerAnimated:YES];
                [hud hideAnimated:YES];
            } failure:^(NSError *error) {
                [hud hideAnimated:YES];
            }];
        }else{
            //Create user
            if([FBSDKAccessToken currentAccessToken] && CurrentUser.userDto && CurrentUser.userDto.facebookID && CurrentUser.userDto.facebookID.length > 0){
                user.facebookID = CurrentUser.userDto.facebookID;
                user.password = [FBSDKAccessToken currentAccessToken].tokenString;
            }
            MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
            hud.label.text = @"Registrando...";
            [UserService registerUser:user success:^(UserDTO *result) {
                UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
                UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"HomeVC"];
                [self.navigationController pushViewController:vc animated:YES];
                [hud hideAnimated:YES];
            } failure:^(NSError *error) {
                [hud hideAnimated:YES];
            }];
        }
}

- (IBAction)onEditCC:(id)sender {
    [self.paymentContext presentPaymentMethodsViewController];
}

#pragma mark - Stripe

-(void)paymentMethodsViewControllerDidCancel:(STPPaymentMethodsViewController *)paymentMethodsViewController{
    [paymentMethodsViewController dismissViewControllerAnimated:YES completion:nil];
}

- (void)paymentContextDidChange:(STPPaymentContext *)paymentContext {
    if(self.paymentContext.selectedPaymentMethod && [self.paymentContext.selectedPaymentMethod isKindOfClass:[STPCard class]]){
        self.viewCC.hidden = NO;
        [self.btnCC setTitle:@"Editar / Agregar" forState:UIControlStateNormal];
        STPCard *card = (STPCard*)self.paymentContext.selectedPaymentMethod;
        self.txtCC.text = [@"**** **** **** " stringByAppendingString:card.last4];
        self.imgCC.image = card.image;
    }else{
        [self.btnCC setTitle:@"Agregar" forState:UIControlStateNormal];
        self.viewCC.hidden = YES;
    }
}

- (void)paymentContext:(STPPaymentContext *)paymentContext
didCreatePaymentResult:(STPPaymentResult *)paymentResult
            completion:(STPErrorBlock)completion {

}

- (void)paymentContext:(STPPaymentContext *)paymentContext
   didFinishWithStatus:(STPPaymentStatus)status
                 error:(NSError *)error {

}

- (void)paymentContext:(STPPaymentContext *)paymentContext didFailToLoadWithError:(NSError *)error {
    // Show the error to your user, etc.
}

@end

onEditCC happens when I tap on a button that says Edit Payment Method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants