Search code examples
iosangularionic-frameworkstripe-paymentscapacitor

Exchange applepay token to stripe token on ionic angular


Project Version:
ionic: 6.16.1
capacitor: 3.0.2
angular: 12.0.5

The situation is that we manage to integrate stripe (google pay and credit cards) on ionic web (no domain since it is a native app, just developed in web). However, we could not make any stripe plugin to recognize apple pay on native IOS or google pay on native Android.

One workaround that we are trying to do is that we try to manually get the apple pay token from other plugin and try to exchange it to the stripe API platform with a stripe token so that we can proceed with the payment (we are using [GitHub - samkelleher/cordova-plugin-applepay: A complete Cordova plugin that adds Apple Pay support.] to get the apple pay token). However, there's no function or API that supports this operation.


Solution

  • I was also looking for a solution on what to do with the output from ApplePay in my Ionic 4 app.

    In case someone is looking to process the output from ApplePay on your Ruby/Sinatra server, here is the code I used. Make sure you have linked up Apple merchant certs with Stripe.

    require 'base64'
    require 'stripe'
    require 'json'
    
    Stripe.api_key = 'sk_test_1234XXXXXXXXXXXXXXXXXXX'
    
    post '/applePayTokenRequest' do
    
      token_attrs = JSON.parse(request.body.read)
      pk_token = Base64.decode64(token_attrs.first["paymentData"])
      puts token_attrs
    
      pk_token_instrument_name = token_attrs.first["paymentMethodDisplayName"]
      pk_token_payment_network = token_attrs.first["paymentMethodNetwork"]
      pk_token_transaction_id = token_attrs.first["transactionIdentifier"]
    
      st_token = Stripe::Token.create(
          :pk_token => pk_token,
          :pk_token_payment_network => pk_token_payment_network,
          :pk_token_transaction_id => pk_token_transaction_id
        )
    
      puts st_token
    
    end