Kasas
Kasas

Reputation: 1216

Paypal iOS always returning same paypal id

we are developing and app that allows the user to add user credit by paypal. In order to do that in iOS we do:

NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
    float value = [[numberFormatter numberFromString:self.tfBalance.text] floatValue];
    value = value * 1.04;
    // Create a PayPalPayment
    PayPalPayment *payment = [[PayPalPayment alloc] init];

    // Amount, currency, and description
    payment.amount = [[NSDecimalNumber alloc] initWithString:[NSString stringWithFormat:@"%.2f", value]];
    payment.currencyCode = @"EUR";
    payment.shortDescription = [NSString stringWithFormat:@"Añadir Saldo: %@+4%% comisión PayPal", self.tfBalance.text];


    payment.intent = PayPalPaymentIntentSale;
    PayPalPaymentViewController *paymentViewController;
    paymentViewController = [[PayPalPaymentViewController alloc] initWithPayment:payment
                                                                   configuration:self.payPalConfiguration
                                                                        delegate:self];

    // Present the PayPalPaymentViewController.
    [self presentViewController:paymentViewController animated:YES completion:nil];

And the delegate:

#pragma mark - PayPal delegate
- (void)payPalPaymentViewController:(PayPalPaymentViewController *)paymentViewController
             didCompletePayment:(PayPalPayment *)completedPayment {
// Payment was processed successfully; send to server for verification and fulfillment.
[self verifyCompletedPayment:completedPayment];

// Dismiss the PayPalPaymentViewController.
[self dismissViewControllerAnimated:YES completion:nil];
}

- (void)payPalPaymentDidCancel:(PayPalPaymentViewController *)paymentViewController {
// The payment was canceled; dismiss the PayPalPaymentViewController.
[self dismissViewControllerAnimated:YES completion:nil];
}

- (void)verifyCompletedPayment:(PayPalPayment *)completedPayment {
// Verificamos en el servidor si se ha realizado el pago
NSDictionary* response = [completedPayment.confirmation objectForKey:@"response"];
NSString* paypalId = [response objectForKey:@"id"];
[[MMApplicationModel sharedInstance].restManager createPayPalOperation:paypalId amount:[completedPayment.amount stringValue] completionHandler:^(bool verified) {
    if(verified){
        [self.tfBalance setText:@""];
        [self performSelectorInBackground:@selector(refreshBalance) withObject:nil];
    }
    else{
        //Mostramos el error
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        [self showMessage:NSLocalizedString(@"topup_error_creating_operation", nil) withTitle:NSLocalizedString(@"error", nil) andTag:0];
    }
}];
}

The thing is that in PayPal SDK documentation, they say:

After a successful payment is made with the MSDK 2.x, the MSDK returns data to your app about the payment (received by the MSDK from the REST API).

{
"client": {
"environment": "sandbox",
"paypal_sdk_version": "2.0.0",
"platform": "iOS",
"product_name": "PayPal iOS SDK;"
},
"response": {
"create_time": "2014-02-12T22:29:49Z",
"id": "PAY-564191241M8701234KL57LXI",
"intent": "sale",
"state": "approved"
},
"response_type": "payment"
}

You server can store the unique payment id value from the above response.

As the paypal id is the identifier to check the paypal operation in the server. But PayPal-SDK for iOS is always returning same id (in Android is working well) so I don't know if it is a sandbox issue or I am doing something wrong.

Has anyone had the same issue?

Thanks in advance

Upvotes: 0

Views: 337

Answers (1)

Romk1n
Romk1n

Reputation: 401

It looks like the library you are using is quite old 2.0.0, so it the creation time. Have you tried reproducing this behavior with latest PayPal SDK https://github.com/paypal/PayPal-iOS-SDK/releases/tag/2.6.1 ?

Upvotes: 2

Related Questions