0

I am trying to add Google and Apple Pay into my Cordova application. My app is connected to a Magento 2 website via rest api.

First time I have tried with Braintree drop-in but in the end I found that they don't support webview because there is no HTTPS. Than switched to plugins, found 2-3, tried all but none doesn't allow me to pay with Google.

Currently I am using this plugin cordova-apple-pay-google-pay

When I try to pay the app crashes.

in config.xml I have:

      <config-file parent="/manifest/application" target="AndroidManifest.xml">
          <meta-data android:name="com.google.android.gms.wallet.api.enabled" android:value="true" />
      </config-file>
      <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
          <application android:usesCleartextTraffic="true" />
      </edit-config>
      <preference name="android-compileSdkVersion" value="32" />
      <preference name="scheme" value="http" />
      <preference name="hostname" value="localhost" />
      <preference name="android-compileSdkVersion" value="32" />
      <preference name="GradlePluginKotlinEnabled" value="true" />
      <preference name="GradlePluginGoogleServicesEnabled " value="true" />
      <preference name="AndroidXEnabled" value="true" />

and the script for payment looks like that:

cordova.plugins.ApplePayGooglePay.canMakePayments((available) => {
    if(!available){
        app.dialog.alert('Google Pay not available');
        return
    }
    var request = {
        countryCode: "GB",
        amount: totals.base_grand_total, // 0.01
        currencyCode: totals.quote_currency_code, //GBP
        gateway: 'braintree', https://developers.google.com/pay/api#participating-processors
        merchantId: 'BRAINTREE-ID', // merchant id provided by your processor
        gpMerchantName: 'Name of Cordova App', // will be displayed in transaction info
        gpMerchantId: 'CODE-FROM-GOOGLE-PAY' // obtain it at https://pay.google.com/business/console
    }
    cordova.plugins.ApplePayGooglePay.makePaymentRequest(request, function(data){
        console.log(data);
    }, function(error){
        console.log(error);
    });
});

Google Pay returns error: Request Failed - Unexpected developer error, please try again later.

In iPhone simulator (iOS 16) tested successfully.

I know that Google pay requires HTTPS too, so my question is does this two payments still work with Cordova? If YES, than how? what do I miss? Thanks

Adrian
  • 491
  • 6
  • 23

0 Answers0