Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RMET-2079 Payments Plugin - Processing a payment using a PSP (Stripe) - Android #20

Merged
merged 27 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7950e13
fix: use fix versions (#17)
alexgerardojacinto Nov 14, 2022
209629e
feat: first implementation of stripe android POC
alexgerardojacinto Nov 15, 2022
720b62e
fix: use createFromGooglePay method
alexgerardojacinto Nov 15, 2022
ce27d26
feat: include POST request to server to process payment with Stripe
alexgerardojacinto Nov 16, 2022
065bf7f
Merging PoC refactor branch into PoC branch (#18)
alexgerardojacinto Dec 2, 2022
be79f3a
refactor: process specific fields instead of whole tokenization JSON
alexgerardojacinto Dec 2, 2022
8aa20a8
refactor: change variable name
alexgerardojacinto Dec 2, 2022
2658711
fix: fixing hook processing of tokenization
alexgerardojacinto Dec 2, 2022
4608e86
refactor: use local lib for development
alexgerardojacinto Dec 2, 2022
ea8e7bf
fix: change lib name
alexgerardojacinto Dec 2, 2022
ecec10b
refactor: update object creation
alexgerardojacinto Dec 2, 2022
e713ff8
refactor: use object for PSP info
alexgerardojacinto Dec 3, 2022
668e1cb
refactor: simple refactors
alexgerardojacinto Dec 4, 2022
27ef2db
chore: update lib
alexgerardojacinto Dec 4, 2022
f8869b3
fix: include stripe dependency in build.gradle
alexgerardojacinto Dec 4, 2022
7d7c4b9
chore: update OSPaymentsLib
alexgerardojacinto Dec 6, 2022
b37a1d8
refactor: remove unnecessary parameters
alexgerardojacinto Dec 6, 2022
6c3e88e
refactor: renamed some classes
alexgerardojacinto Dec 7, 2022
ead94bb
chore: update lib
alexgerardojacinto Dec 7, 2022
a6f6a53
chore: update lib
alexgerardojacinto Dec 7, 2022
abbb29c
chore: update changelog
alexgerardojacinto Dec 7, 2022
0138ca4
Merge branch 'development' into feat/RMET-2079/android-stripe
alexgerardojacinto Dec 7, 2022
ebb6734
feat: use lib from azure instead of local
alexgerardojacinto Dec 7, 2022
1812560
chore: update lib version
alexgerardojacinto Dec 8, 2022
4acb701
chore: update lib version
alexgerardojacinto Dec 12, 2022
c57f263
fix: remove dependencies to jcenter
alexgerardojacinto Dec 16, 2022
91897df
Merge branch 'development' into feat/RMET-2079/android-stripe
alexgerardojacinto Dec 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ The changes documented here do not include those from the original repository.

## [Unreleased]

## 16-12-2022
Android - remove dependency to jcenter (https://outsystemsrd.atlassian.net/browse/RMET-2036)

## 07-12-2022
Android - implemented payment processing using Stripe (https://outsystemsrd.atlassian.net/browse/RMET-2079)

- Fix: [Android] Use fixed versions instead of dynamic ones. (https://outsystemsrd.atlassian.net/browse/RMET-2045)

### 2022-12-02
- Chore: [iOS] Remove all the `OSPaymentsLib` files and replace them by the new `OSPaymentsPluginLib` pod.
- Feat: [iOS] Update hook so that it checks if Stripe's is configured as the Payment Service Provider and update `plist` file accordingly (https://outsystemsrd.atlassian.net/browse/RMET-2078).
Expand Down
47 changes: 41 additions & 6 deletions hooks/android/androidCopyPreferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ module.exports = function (context) {
const ServiceEnum = Object.freeze({"ApplePay":"1", "GooglePay":"2"})
const configFileName = 'www/json-config/PaymentsPluginConfiguration.json';

var hasGooglePay = false;

var merchant_name = "";
var merchant_country_code = "";
var payment_allowed_networks = [];
Expand All @@ -15,8 +17,13 @@ module.exports = function (context) {
var shipping_supported_contacts = [];
var shipping_country_codes = [];
var billing_supported_contacts = [];
var tokenization = "";
var hasGooglePay = false;
var gateway = "";
var backend_url = "";
//only for PSPs other than Stripe
var gateway_merchant_id = "";
//only for stripe
var stripe_version = "";
var stripe_pub_key = "";


var projectRoot = context.opts.cordova.project ? context.opts.cordova.project.root : context.opts.projectRoot;
Expand Down Expand Up @@ -81,7 +88,15 @@ module.exports = function (context) {
}

if(configItem.tokenization){
tokenization = JSON.stringify(configItem.tokenization);
gateway = configItem.tokenization.gateway;
backend_url = configItem.tokenization.requestURL;
if(gateway.toUpperCase() == "STRIPE"){
stripe_version = configItem.tokenization.stripeVersion;
stripe_pub_key = configItem.tokenization.stripePublishableKey;
}
else{
gateway_merchant_id = configItem.tokenization.gatewayMerchantId;
}
}
else{
error_list.push('PSP information');
Expand Down Expand Up @@ -139,9 +154,29 @@ module.exports = function (context) {
billingContactsTags[i].text = billing_supported_contacts;
}

var tokenizationTags = etreeStrings.findall('./string[@name="tokenization"]');
for (var i = 0; i < tokenizationTags.length; i++) {
tokenizationTags[i].text = tokenization;
var gatewayTags = etreeStrings.findall('./string[@name="gateway"]');
for (var i = 0; i < gatewayTags.length; i++) {
gatewayTags[i].text = gateway;
}

var backendUrlTags = etreeStrings.findall('./string[@name="backend_url"]');
for (var i = 0; i < backendUrlTags.length; i++) {
backendUrlTags[i].text = backend_url;
}

var gatewayMerchantIdTags = etreeStrings.findall('./string[@name="gateway_merchant_id"]');
for (var i = 0; i < gatewayMerchantIdTags.length; i++) {
gatewayMerchantIdTags[i].text = gateway_merchant_id;
}

var stripeVersionTags = etreeStrings.findall('./string[@name="stripe_version"]');
for (var i = 0; i < stripeVersionTags.length; i++) {
stripeVersionTags[i].text = stripe_version;
}

var stripePubKeyTags = etreeStrings.findall('./string[@name="stripe_pub_key"]');
for (var i = 0; i < stripePubKeyTags.length; i++) {
stripePubKeyTags[i].text = stripe_pub_key;
}

var resultXmlStrings = etreeStrings.write();
Expand Down
6 changes: 5 additions & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
<string name="shipping_supported_contacts">SHIPPING_SUPPORTED_CONTACTS</string>
<string name="shipping_country_codes">SHIPPING_COUNTRY_CODES</string>
<string name="billing_supported_contacts">BILLING_SUPPORTED_CONTACTS</string>
<string name="tokenization">TOKENIZATION</string>
<string name="gateway">GATEWAY</string>
<string name="backend_url">BACKEND_URL</string>
<string name="gateway_merchant_id">GATEWAY_MERCHANT_ID</string>
<string name="stripe_version">STRIPE_VERSION</string>
<string name="stripe_pub_key">STRIPE_PUB_KEY</string>
</config-file>

<source-file src="src/android/com/outsystems/payments/OSPayments.kt" target-dir="app/src/main/kotlin/com/outsystems/payments"/>
Expand Down
54 changes: 34 additions & 20 deletions src/android/com/outsystems/payments/OSPayments.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,29 @@ package com.outsystems.payments
import android.app.Activity
import android.content.Intent
import com.google.gson.Gson
import org.apache.cordova.CallbackContext
import com.outsystems.plugins.oscordova.CordovaImplementation
import com.outsystems.plugins.payments.controller.GooglePayManager
import com.outsystems.plugins.payments.controller.GooglePlayHelper
import com.outsystems.plugins.payments.controller.PaymentsController
import com.outsystems.plugins.payments.controller.OSPMTGooglePayManager
import com.outsystems.plugins.payments.controller.OSPMTGooglePlayHelper
import com.outsystems.plugins.payments.controller.OSPMTController
import com.outsystems.plugins.payments.model.OSPMTError
import com.outsystems.plugins.payments.model.PaymentConfigurationInfo
import com.outsystems.plugins.payments.model.PaymentDetails
import com.outsystems.plugins.payments.model.PaymentsError
import com.outsystems.plugins.payments.model.Tokenization
import kotlinx.coroutines.runBlocking
import org.apache.cordova.CallbackContext
import org.apache.cordova.CordovaInterface
import org.apache.cordova.CordovaWebView
import org.json.JSONArray

class OSPayments : CordovaImplementation() {

override var callbackContext: CallbackContext? = null
private lateinit var googlePayManager: GooglePayManager
private lateinit var paymentsController: PaymentsController
private lateinit var googlePlayHelper: GooglePlayHelper
private lateinit var googlePayManager: OSPMTGooglePayManager
private lateinit var paymentsController: OSPMTController
private lateinit var googlePlayHelper: OSPMTGooglePlayHelper

//to delete
private var paymentDetails: PaymentDetails? = null

val gson by lazy { Gson() }

Expand All @@ -35,14 +39,18 @@ class OSPayments : CordovaImplementation() {
private const val SHIPPING_SUPPORTED_CONTACTS = "shipping_supported_contacts"
private const val SHIPPING_COUNTRY_CODES = "shipping_country_codes"
private const val BILLING_SUPPORTED_CONTACTS = "billing_supported_contacts"
private const val TOKENIZATION = "tokenization"
private const val GATEWAY = "gateway"
private const val BACKEND_URL = "backend_url"
private const val GATEWAY_MERCHANT_ID = "gateway_merchant_id"
private const val STRIPE_VERSION = "stripe_version"
private const val STRIPE_PUB_KEY = "stripe_pub_key"
}

override fun initialize(cordova: CordovaInterface, webView: CordovaWebView) {
super.initialize(cordova, webView)
googlePayManager = GooglePayManager(getActivity())
googlePlayHelper = GooglePlayHelper()
paymentsController = PaymentsController(googlePayManager, buildPaymentConfigurationInfo(getActivity()), googlePlayHelper)
googlePayManager = OSPMTGooglePayManager(getActivity())
googlePlayHelper = OSPMTGooglePlayHelper()
paymentsController = OSPMTController(googlePayManager, buildPaymentConfigurationInfo(getActivity()), googlePlayHelper)
}

override fun execute(action: String, args: JSONArray, callbackContext: CallbackContext): Boolean {
Expand Down Expand Up @@ -89,27 +97,27 @@ class OSPayments : CordovaImplementation() {
private fun setDetailsAndTriggerPayment(args: JSONArray){
setAsActivityResultCallback()

val paymentDetails = buildPaymentDetails(args)
paymentDetails = buildPaymentDetails(args)

if(paymentDetails != null){
paymentsController.setDetailsAndTriggerPayment(getActivity(), paymentDetails
paymentsController.setDetailsAndTriggerPayment(getActivity(), paymentDetails!!
) {
sendPluginResult(null, Pair(formatErrorCode(it.code), it.description))
}
}
else{
sendPluginResult(null, Pair(formatErrorCode(PaymentsError.INVALID_PAYMENT_DETAILS.code), PaymentsError.INVALID_PAYMENT_DETAILS.description))
sendPluginResult(null, Pair(formatErrorCode(OSPMTError.INVALID_PAYMENT_DETAILS.code), OSPMTError.INVALID_PAYMENT_DETAILS.description))
}
}

override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent) {
super.onActivityResult(requestCode, resultCode, intent)
paymentsController.handleActivityResult(requestCode, resultCode, intent,
{
sendPluginResult(it, null)
{ paymentResponse ->
sendPluginResult(paymentResponse, null)
},
{
sendPluginResult(null, Pair(formatErrorCode(it.code), it.description))
{ error ->
sendPluginResult(null, Pair(formatErrorCode(error.code), error.description))
})
}

Expand Down Expand Up @@ -143,7 +151,13 @@ class OSPayments : CordovaImplementation() {
if(shippingContacts.isNotEmpty() && shippingContacts[0].isNotEmpty()) shippingContacts else listOf(),
if(shippingCountries.isNotEmpty() && shippingCountries[0].isNotEmpty()) shippingCountries else listOf(),
if(billingContacts.isNotEmpty() && billingContacts[0].isNotEmpty()) billingContacts else listOf(),
activity.getString(getStringResourceId(activity, TOKENIZATION))
Tokenization(
activity.getString(getStringResourceId(activity, GATEWAY)),
activity.getString(getStringResourceId(activity, BACKEND_URL)),
activity.getString(getStringResourceId(activity, GATEWAY_MERCHANT_ID)),
activity.getString(getStringResourceId(activity, STRIPE_VERSION)),
activity.getString(getStringResourceId(activity, STRIPE_PUB_KEY))
)
)
}

Expand Down
8 changes: 4 additions & 4 deletions src/android/com/outsystems/payments/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.+'
classpath 'com.android.tools.build:gradle:3.6.4'
}
}

Expand All @@ -19,7 +18,6 @@ repositories {
}

repositories{
jcenter()
flatDir {
dirs 'src/main/libs'
}
Expand All @@ -31,7 +29,9 @@ apply plugin: 'kotlin-kapt'
dependencies {
implementation("com.github.outsystems:oscore-android:1.1.0@aar")
implementation("com.github.outsystems:oscordova-android:1.1.0@aar")
implementation("com.github.outsystems:ospayments-android:1.0.0@aar")
implementation("com.github.outsystems:ospayments-android:1.0.3@aar")

implementation 'com.stripe:stripe-android:20.5.0'

implementation 'androidx.appcompat:appcompat:1.4.1'
implementation "com.google.android.gms:play-services-wallet:19.1.0"
Expand Down