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

Fixed problems with selection of PayPal environment #662

Merged
merged 2 commits into from
Oct 9, 2016

Conversation

patrickbussmann
Copy link
Contributor

After I fixed the other #653 problem I find out that I'm unable to leave the "NoNetwork" mock environment.
So I searched for a solution and I found out that the PayPal scripts are not up to date with the cordova plugin repository.

With this update we are able to use PayPal via ionic-native in production and sandbox environments. So we can work with IPN's and everything and test as we like.

Example pay flow...

import {PayPal, PayPalPayment, PayPalConfiguration} from "ionic-native";

[...]

PayPal.init({
    "PayPalEnvironmentProduction": "YOUR_PRODUCTION_CLIENT_ID",
    "PayPalEnvironmentSandbox": "YOUR_SANDBOX_CLIENT_ID"
}).then(() => {
    /** Environments: PayPalEnvironmentNoNetwork, PayPalEnvironmentSandbox, PayPalEnvironmentProduction */
    PayPal.prepareToRender('PayPalEnvironmentSandbox', new PayPalConfiguration({
        /** Only needed if you get an "Internal Service Error" after PayPal login! */
        //payPalShippingAddressOption: 2 // PayPalShippingAddressOptionPayPal
    })).then(() => {
        let payment = new PayPalPayment('3.33', 'USD', 'Description', 'intent');
        PayPal.renderSinglePaymentUI(payment).then(() => {
            // Successfully paid

            /**
             * Example sandbox response
             *
             * {
             *   "client": {
             *     "environment": "sandbox",
             *     "product_name": "PayPal iOS SDK",
             *     "paypal_sdk_version": "2.16.0",
             *     "platform": "iOS"
             *   },
             *   "response_type": "payment",
             *   "response": {
             *     "id": "PAY-1AB23456CD789012EF34GHIJ",
             *     "state": "approved",
             *     "create_time": "2016-10-03T13:33:33Z",
             *     "intent": "sale"
             *   }
             * }
             */
        }, () => {
            // Error or render dialog closed without being successful
        });
    }, () => {
        // Error in configuration
    });
}, () => {
    // Error in initialization, maybe PayPal isn't supported or something else
});

I had a error with the login to PayPal after switching from the Mock-NoNetwork environment to the sandbox environment. "Internal Service error". After play around a bit with the PayPal Sample iOS App I found out that I must set the optional payPalShippingAddressOption to PayPalShippingAddressOptionPayPal. I added this in the example above so that you can do the same if you have the same issue. 👍

@ihadeed
Copy link
Collaborator

ihadeed commented Oct 9, 2016

thanks @patrickbussmann

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

Successfully merging this pull request may close these issues.

2 participants