tolu360 / cordova-plugin-paystack

This plugin allows to add Paystack Payments to your application using Paystack Native Mobile SDKs for Android & iOS
Other
34 stars 16 forks source link

Error with PublishableKey #4

Closed darmie closed 8 years ago

darmie commented 8 years ago

This is my config.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget xmlns:android="http://schemas.android.com/apk/res/android" id="ng.push.userapp" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">

  <name>MyApp</name>
  <description>
      Info
  </description>
  <author email="" href="">

  </author>
  <content src="index.html"/>
  <access origin="*"/>
  <preference name="webviewbounce" value="false"/>
  <preference name="UIWebViewBounce" value="false"/>
  <preference name="DisallowOverscroll" value="true"/>
  <preference name="android-minSdkVersion" value="16"/>
  <preference name="BackupWebStorage" value="none"/>
  <preference name="SplashScreen" value="screen"/>
  <preference name="SplashScreenDelay" value="5000"/>
  <preference name="ShowSplashScreenSpinner" value="false" />
  <config-file target="AndroidManifest.xml" parent="application">
    <meta-data android:name="co.paystack.android.PublishableKey" android:value="my key"/>
  </config-file>
  <preference name="publishableKey" value="my key" />
  <feature name="StatusBar">
    <param name="ios-package" value="CDVStatusBar" onload="true"/>
  </feature>
</widget>

I am getting this error when I tried to use paystack

05-19 14:20:14.010: E/PaystackPlugin(3195): No Publishable key found, please set the Publishable key.
05-19 14:20:14.010: W/CordovaPlugin(3195): Attempted to send a second callback for ID: PaystackPlugin1003071714
05-19 14:20:14.010: W/CordovaPlugin(3195): Result was: "Invalid action"

My Code

//NEW CARD
    $scope.cardDetails = {}
    $scope.newCard = function(){
      window.PaystackPlugin.getToken(
        function(resp) {
          // A valid one-timme-use token is obtained, do your thang!
          console.log('Paystack success: ', JSON.stringify(resp));
          //$scope.listCards()
        },
        function(resp) {
          // Something went wrong, oops - perhaps an invalid card.
          console.log('Paystack failure: ', JSON.stringify(resp));
        },
        $scope.cardDetails.number,
        $scope.cardDetails.month.getMonth(),
        $scope.cardDetails.month.getFullYear(),
        $scope.cardDetails.cvv);
    }
tolu360 commented 8 years ago

Please check that your android config in your config.xml file is inserted within <platform> tags as shown below, build your app again and try to use the plugin again:

<platform name="android">
<config-file target="AndroidManifest.xml" parent="application">
    <meta-data android:name="co.paystack.android.PublishableKey" android:value="INSERT-PUBLIC-KEY-HERE"/>
</config-file>
</platform>
darmie commented 8 years ago

That solved it. Thanks.

darmie commented 8 years ago

The token is being created but it doesn't return as a value in the Javascript success call back

05-19 14:43:13.280: I/PaystackPlugin(11213): PSTK_17ejvt040djfepr
05-19 14:43:13.290: I/chromium(11213): [INFO:CONSOLE(121)] "Paystack success: ", source: file:///android_asset/www/js/controllers.js (121)
tolu360 commented 8 years ago

Leave out the JSON.stringify() function to see what format the plugin response comes through first, then you can add it back on subsequently. Both the success and error callbacks return objects.

$scope.newCard = function(){
      window.PaystackPlugin.getToken(
        function(resp) {
          // A valid one-timme-use token is obtained, do your thang!
          console.log('Paystack success: ', resp);
          //$scope.listCards()
        },
        function(resp) {
          // Something went wrong, oops - perhaps an invalid card.
          console.log('Paystack failure: ', resp);
        },
        $scope.cardDetails.number,
        $scope.cardDetails.month.getMonth(),
        $scope.cardDetails.month.getFullYear(),
        $scope.cardDetails.cvv);
};
darmie commented 8 years ago

Yes I have removed it and the result is still the same.

tolu360 commented 8 years ago

Ensure you are calling the plugin within a normal Cordova deviceready or Ionic's Platform.ready() event just to prevent any race condition. Then always recompile your app when you make changes to your code using a plugin by running build again.

darmie commented 8 years ago

Fixed:

The second argument resp in console.log("Paystack success ", resp) is being ignored b chromium.

this is how i got to see the response from the call back console.log("Paystack success " + resp) , using the + sign

tolu360 commented 8 years ago

Ok, glad you figured it out. You may try console.log(resp) alone anyway, most likely you'd be assigning the token to a local variable after all. Cheers!

darmie commented 8 years ago

Sure!