3

I've added Stripe integration into our app and I'm having a problem when the user first adds a card. The card gets added successfully but when I try and update the default source I get the error No such source: card-xxxxxxxxxxxx, but if I go back to the view to the "add a card" and reselect the same card thats been added, the defaultSource update works and I can make a payment.

My attachSourceToCustomer is as follows:

  -(void)attachSourceToCustomer:(id<STPSource>)source completion:(STPErrorBlock)completion {
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

    [manager setRequestSerializer:[AFJSONRequestSerializer serializer]];
    [[SBCommon sharedInstance].currentAccount addAuthorization:manager.requestSerializer];

    NSString * sourceId = source.stripeID;
    NSDictionary * params =@{@"stripeSource": sourceId};

    [manager POST:[NSString stringWithFormat:kSBBaseAPIURL,@"StripeCustomerSource"] parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"%@ success: %@",NSStringFromClass([self class]),operation.responseObject);
        completion(nil);

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                  NSLog(@"%@ failed: %@",NSStringFromClass([self class]),operation.responseObject);
    completion(error);
    }];
}

and my selectDefaultCustomer as as follows

-(void)selectDefaultCustomerSource:(id<STPSource>)source completion:(STPErrorBlock)completion {
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

[manager setRequestSerializer:[AFJSONRequestSerializer serializer]];
    [[SBCommon sharedInstance].currentAccount addAuthorization:manager.requestSerializer];

    NSString * sourceId = source.stripeID;
    NSDictionary * params =@{@"stripeSource": sourceId};

    [manager POST:[NSString stringWithFormat:kSBBaseAPIURL,@"StripeCustomerDefaultSource"] parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"%@ success: %@",NSStringFromClass([self class]),operation.responseObject);
        completion(nil);

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@ failed: %@",NSStringFromClass([self class]),operation.responseObject);
        completion(error);
    }];
}

I must be missing something I need to do when the user adds the card, but I can't see from the documentation anything that I'm missing

UPDATE It would appear that the SDK doesn't work if you are using Connect, the card_id returned to selectDefaultCustomer doesn't actually match the one created on the Customer that is owned by the Connect account. The paymentContext can't be updated so when a paymentRequest is made its using the incorrect card_id and fails

Flexicoder
  • 8,251
  • 4
  • 42
  • 56

0 Answers0