I have already setup the paypal plugin and the sandbox environment and it works fine, but whenever there should be a failed transaction for example
-
Not enough credits on the buyer account
-
Wrong information on the credit card
The final result is always status “approved” even thought it should have Failed
This is the code i use,
paypalPayment(orderId, postdataTransfer, policyAmountPay) {
var policyAmount = policyAmountPay;
var currency = this.brokerCurrency.toString().trim();
var description = 'Policy';
var intent = 'sale';
this.payPal.init({
PayPalEnvironmentProduction: '',
PayPalEnvironmentSandbox: 'MySandboxID' //i replace this with the key,just didn't want to share
}).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(() => {
let payment = new PayPalPayment(policyAmount, currency, description, intent);
payment.invoiceNumber = orderId.toString();
this.payPal.renderSinglePaymentUI(payment).then((response) => {
console.log('Payment test : ' + payment.amount);
console.log('Invoice number : ' + payment.invoiceNumber);
console.log('state : ' + response.response.state);
console.log('create_time : ' + response.response.create_time);
console.log('intent : ' + response.response.intent);
console.log('response_type : ' + response.response_type);
console.log('environment : ' + response.client.environment);
console.log('platform : ' + response.client.platform);
console.log('Response : ' + response.response.id);
console.log('All keys : ' + Object.keys(response))
console.log('All keys - Client : ' + Object.keys(response.client))
console.log('All keys - response_type : ' + Object.keys(response.response_type))
console.log('All keys - response : ' + Object.keys(response.response))
//check if it is approved
//if it is approved then we send thank you msg + paypal parameters + update policy status
if (response.response.state === 'approved') {
//send the parameters to checkoutfinish
// this.navCtrl.push(CheckoutFinishPage, { code: 1001, orderId: payment.invoiceNumber, postdataTransfer: postdataTransfer, redeemPoints: this.myFormGroup.value['txtRedeemPoints'] });
}
else {
// if (response.response.state === 'failed')
this.navCtrl.push(CheckoutFinishPage, { code: 1002 });
}
//send error msg to checkoutfinish
// 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
this.navCtrl.push(CheckoutFinishPage, { code: 1003, paypalErrorMsg: this.translate.instant('Paypal.errorMsg1003') });
});
}, () => {
// Error in configuration
this.navCtrl.push(CheckoutFinishPage, { code: 1004, paypalErrorMsg: this.translate.instant('Paypal.errorMsg1004') });
});
}, () => {
// Error in initialization, maybe PayPal isn't supported or something else
this.navCtrl.push(CheckoutFinishPage, { code: 1005, paypalErrorMsg: this.translate.instant('Paypal.errorMsg1005') });
});
}
Thank you for all your help