ionic3 native paypal init error - ionic-framework

I am doing an integration between my ionic3 app and Paypal, I am following the doc from official ionic native paypal plugin website. But when I press the button to trigger the paypal, it refresh to the root page of the app.
Here is my code:
gotoPaypal(){
this.pppayment = new PayPalPayment('3.33', 'USD', 'Description', 'sale');
this.payPal.init({
PayPalEnvironmentProduction: 'dgdfghfjfhgjghjadsasfdsdfsghkgjkjhk',
PayPalEnvironmentSandbox: 'hasvahgsdvajbdhgvcasdh sahgdvasdvagksd'
}).then(() => {
this.payPal.prepareToRender('PayPalEnvironmentSandbox', new PayPalConfiguration({
})).then(() => {
this.payPal.renderSinglePaymentUI(this.pppayment).then(() => {
}, () => {
console.log("Paypal 3333");
});
}, () => {
console.log("Paypal 2222");
});
}, () => {
console.log("Paypal 1111");
});
}
And before it's auto refresh, I see console printed "Paypal 1111", so I think init Paypal have error, Anyone know what happen or how to fix?

Related

Ionic app: Keeping the screen unlock and open when the ionic app is up and running

I'm developing a navigation app with Ionic framework. Is there a way to keep the screen of the device open while the app is up and running ?
Yes you can Keep screen Active:
There is a cordova plugin for this:
ionic cordova plugin add cordova-plugin-insomnia
npm install #ionic-native/insomnia
import { Insomnia } from '#ionic-native/insomnia/ngx';
constructor(private insomnia: Insomnia) { }
...
this.insomnia.keepAwake()
.then(
() => console.log('success'),
() => console.log('error')
);
this.insomnia.allowSleepAgain()
.then(
() => console.log('success'),
() => console.log('error')
)
Check Plugin Docs here Cordova Insomnia Docs
The answer by Najam Us Saqib is correct but for some minor corrections.
Corrections to the above answer: The IONIC Native package doesnt exist anymore. We need to use Awesome-Cordova-plugins package.
npm install #awesome-cordova-plugins/insomnia
A slightly modified version of the code would be
import { Insomnia } from '#awesome-cordova-plugins/insomnia/ngx';
export class MyComponent implements OnInit, OnDestroy {
constructor(private insomnia: Insomnia) {
this.insomnia.keepAwake()
.then(
() => console.log('success'),
() => console.log('error')
);
}
ngOnDestroy() {
...
this.insomnia.allowSleepAgain()
.then(
() => console.log('success'),
() => console.log('error')
);
...
}
}
The above code will keep the app awake as long as this component is in the stack. Once the component is destroyed, the app will allow the device to sleep again.

Payments to this merchant are not allowed (invalid clientId) - Ionic iOS

Im using the paypal plugin for ionic and is not working on iOS
I already have running this plugin on android and it is working perfect, and also have the clientid generated on https://developer.paypal.com/developer/applications/
doPayment() {
const total: any = 10;
const currency: any = 'USD';
const envProduct: any = '';
const envSandbox: any = '{Client ID from developer.paypal.com/developer/applications/}';
this.payPal.init({
PayPalEnvironmentProduction: envProduct,
PayPalEnvironmentSandbox: envSandbox
})
.then(() => {
// Environments: PayPalEnvironmentNoNetwork, PayPalEnvironmentSandbox, PayPalEnvironmentProduction
this.payPal.prepareToRender('PayPalEnvironmentSandbox', new PayPalConfiguration({
// Only needed if you get an "Internal Service Error" after PayPal login!
// payPalShippingAddressOption: 2 // PayPalShippingAddressOptionPayPal
})).then(() => {
const payment = new PayPalPayment(total, currency, 'Description', 'sale');
this.payPal.renderSinglePaymentUI(payment).then(async ( res ) => {
// rest of the code after payment
}, ( errclose ) => {
console.log( errclose ); // Error or render dialog closed without being successful
});
}, ( errconf ) => {
console.log( errconf ); // Error in configuration
});
}, ( errinit ) => {
console.log( errinit ); // Error in initialization, maybe PayPal isn't supported or something else
});
}
Here is the Error:
Payments to this merchant are not allowed (invalid clientId)
Any help is appreciated. Thank you very much.
I get the same error, also on iOS only, when used Ionic Capacitor for runtime instead of Cordova. When I built the app using Cordova runtime it worked correctly on both platforms. Also, you could get the same error when specifying the 'PayPalEnvironmentSandbox' environment name but use production clientId and vice versa.

Paypal webhooks events are not triggered in sandbox

Hello I am using the following setup
Created paypal merchant and customer sandbox accounts
Configured paypal REST API app
Added a webhook url to my server and have validated that it works using the webhook simulator
Used the Express Checkout javascript implementation found here
I am able to make successful payments when viewing the notifications in sandbox but no webhook is ever triggered???
Below is a sample of my javascript implementation that I have used, please not that it's embedded in a coldfusion script file hence the use hashtags.
`
var items = #paypalItems#;
// Render the PayPal button
paypal.Button.render({
env: '#application.config.paypal.bSandbox ? "sandbox" : "production"#', // sandbox | production
commit: true,
//style the button
style: {
label: 'pay'
},
// PayPal Client IDs - replace with your own
client: {
sandbox: '#application.config.paypal.sandbox_key#',
production: '#application.config.paypal.live_key#'
},
// Wait for the PayPal button to be clicked
payment: function(data, actions) {
// Make a client-side call to the REST api to create the payment
return actions.payment.create({
payment: {
transactions: [{
amount: {
total: #trim(numberFormat( application.oCart.getTotal(bDiscount=1,bShipping=1) , "99999999.99" ))#,
currency: "AUD",
details: {
subtotal: #trim(numberFormat( application.oCart.getTotal() - application.oCart.getAmountGST( amount=application.oCart.getTotal(bDiscount=1), addGST=false ), "99999999.99" ))#,
tax: #trim(numberFormat(application.oCart.getAmountGST( amount=application.oCart.getTotal(bDiscount=1), addGST=false ), "99999999.99" ))#,
shipping: #trim(numberFormat( application.oCart.oShipping.getCartShippingAmount(country=session.fcbshoppingCart.order.shippingCountry), "99999999.99" ))#
}
},
invoice_number: "#orderNumber#",
item_list: {
items: items,
shipping_address: {
recipient_name: "#session.fcbshoppingCart.customer.firstName# #session.fcbshoppingCart.customer.lastName#",
line1: "#session.fcbshoppingCart.order.shippingAddress1#",
line2: "#session.fcbshoppingCart.order.shippingAddress2#",
city: "#session.fcbshoppingCart.order.shippingSuburb#",
country_code: "#paypalCountryCode#",
postal_code: "#session.fcbshoppingCart.order.shippingPostCode#",
state: "#session.fcbshoppingCart.order.shippingState#"
}
}
}]
}
});
},
// Wait for the payment to be authorized by the customer
onAuthorize: function(data, actions) {
console.log( "Paypal Authorize:", data );
// Execute the payment
return actions.payment.execute().then(function(payment) {
console.log( "Paypal Response:", payment );
//payment has been accepted so we can now generate an order
$.ajax({
type: "get",
url: "/apps/paypal/createOrder.cfm",
data: {
transactionNumber: "#orderNumber#",
payPalPaymentId: data.paymentID
},
dataType: "json",
success: function( res ) {
console.log('edharry create order data', res);
if( res.BPAYMENTPROCEED ) {
$('##paypal-message').addClass("show success").text('Payment Successfully Complete!');
//lets redirect to the checkout success page.
window.location.href = window.location.origin + '/shop/checkout/confirmation?productOrder=' + res.PRODUCTORDER.OBJECTID;
} else {
//need to handle a failed transaction
$('##paypal-message').addClass("show failure").text('Payment did not complete on server!');
}
},
error: function() {
//lets show an error
$('##paypal-message').addClass("show failure").text('Payment did not complete on server!');
}
})
$('##paypal-message').addClass("show success").text('Payment Successfully Complete!');
});
},
onCancel: function(data) {
console.log('The payment was cancelled!');
}
}, '##paypal-button-container');`
This is an ongoing issue with Paypal. They are aware of this issue and are currently working to resolve this.

Best way to exeute various tests in protractor for various login id's

I have to test application using protractor for various different types of users. userid determines the type of user( Admin or partner or user). For all users i need to test the application for all major functionality. Here is what i want to do
Login User 1 > execute test1, test 2, test 3 .... Logout
Login user 2 > execute test1, test 2, test 3 .... Logout
Login User 3 > execute test1, test 2, test 3 .... Logout
Login User 4 > execute test1, test 2, test 3 .... Logout
I want to create a test framework to cover the scenario. I would appreciate inputs on best way to achieve this.
You could do this in a couple of ways. There are pro's and con's to each.
The first way is to just loop over the list of users.
describe('your suite', () => {
for (let user of users) {
describe('test for user: ' + user.username, () => {
beforeAll(() => { login(user) });
it('should do a test', () => {
// test code with user
});
it('should do another test', () => {
// test code with user
});
afterAll(() => { logout(user) });
});
}
});
Another way is to define your callback functions then compose your tests for each user.
testCallback1 = function() {
// test code with user
}
testCallback2 = function() {
// test code with user
}
describe('test for user'), () => {
let user = users[0];
beforeAll(() => { login(user) });
it('should do a test', testCallback1);
it('should do another test', testCallback2);
afterAll(() => { logout(user) });
});
describe('test for user'), () => {
let user = users[1];
beforeAll(() => { login(user) });
it('should do a test', testCallback1);
it('should do another test', testCallback2);
afterAll(() => { logout(user) });
});
There is probably a better way to do this. These are just a couple of suggestions.
I have a similar scenario and here is how I've tackled it. I added an array of users in the protractor config and then I can loop through those users to run my login tests. It's essentially the same setup as the first suggestion by cnishina in his answer. The difference for me is that my test code lives in one file and I have the code that gets the users and loops through them in another file. Probably overkill for a simple scenario but we have several different types of users (admin, non-admin, users with services, users without services, etc.) to run the login tests against so this helps to simplify that situation. I'm using TypeScript but the same thing can be done with JS if that's what you are using.
//in the protractor config
params: {
loginUsers: [
"login1#domain.test",
"login2#domain.test",
"login3#domain.test",
//and so on ...
]
}
Then I have a file where my login tests live called shared-login.tests.ts
export default class SharedLoginTests {
public static sharedSetup(url: string): void {
beforeEach(() => {
//shared setup code ...
}
afterEach(() => {
//shared tear down code ...
}
}
public static executeSharedLoginTests(username: string): void {
it(`should allow ${username} to login`, () => {
//login test code ...
}
}
}
And then I have login.tests.ts like this:
import { browser } from "protractor";
import SharedLoginTests from "./shared-login.tests";
describe(testtitle, () => {
const users: string[] = browser.params.loginUsers;
SharedLoginTests.sharedSetup(browser.params.baseUrl);
for (const user of users) {
SharedLoginTests.executeSharedLoginTests(user);
}
});

.then of $cordovaInAppBrowser is not working

In an Ionic app, I am using ngCordova's $cordovaInAppBrowser to open Apple Play Store URL. It opens the app store but it does not go into .then. Relevant code:
$cordovaInAppBrowser.open(mktUrl, '_system', {location: 'yes', clearcache: 'yes', toolbar: 'no'}).
then(function(event) { ¬
console.log("inside then"); ¬
$state.go('odetails');
}¬
mktUrl is a app store URL for an app.
It does not generate any error. But it just doesn't work. How can I solve the problem?
Been there.
If you change from _system to _blank, cordova uses same webview as your app container and the promises do work.
I am using this code:
var inAppBrowserOptions = {
location: 'yes',
clearcache: 'no',
hardwareback: 'no'
};
if (!site.toLowerCase().match(/^htt(p|ps):\/\//)) {
site = 'http://' + site;
}
$cordovaInAppBrowser.open(
site,
'_blank',
inAppBrowserOptions
).then(function (event) { // success
//$state.go('')
Toast.show('inAppBrowser success', 'short', 'bottom');
}).catch(function (event) { // error
Toast.show('Error opening site', 'short', 'bottom');
});
$rootScope.$on('$cordovaInAppBrowser:exit', function (e, event) {
Toast.show('inAppBrowser exit', 'short', 'bottom');
});