protoncore_android/payment
proton-ci 6880bb0eb7 i18n: Upgrade translations from crowdin (9115a3a2). 2024-04-30 10:13:51 +00:00
..
dagger feat!: Added Purchase, Manager, Repository, StateHandlers and Workers. 2024-03-14 12:06:21 +01:00
data feat!: Added Purchase, Manager, Repository, StateHandlers and Workers. 2024-03-14 12:06:21 +01:00
domain feat: Added CreateAccountNeeded handling. 2024-03-14 12:06:22 +01:00
presentation i18n: Upgrade translations from crowdin (9115a3a2). 2024-04-30 10:13:51 +00:00
README.md Upgraded Hilt to 2.35.1. 2021-05-12 23:33:42 +02:00
build.gradle.kts chore!: Upgraded AGP to 8.0.2 (+Java 17). 2023-07-04 16:22:38 +02:00

README.md

Overview

Modules under Payment provide payments functionality for all Proton services. It supports payment for upgrade of the current logged in account or paying for paid account during sign up.

Gradle

implementation "me.proton.core:payment:{version}"

Payment options

  • Upgrade for the primary user. Can upgrade to any paid plan the primary user. This will create new subscription.
  • Payment for paid plan during sign up. This won't create new subscription, but instead the result token should be used as a header (human verification header with type "payment"). This is responsibility of a Sign Up module however.

Integration guide

Dependencies

  • A few dependencies should be satisfied. Below is an example of Dagger Hilt payments module how should be look like.
@Module
@InstallIn(SingletonComponent::class)
object PaymentsModule {

    @Provides
    @Singleton
    fun providePaymentsRepository(apiProvider: ApiProvider): PaymentsRepository =
        PaymentsRepositoryImpl(apiProvider)

    @Provides
    @Singleton
    fun provideCountriesRepository(@ApplicationContext context: Context): CountriesRepository =
        CountriesRepositoryImpl(context)


    @Provides
    @Singleton
    fun provideSecureEndpoint(): SecureEndpoint = SecureEndpoint("secure.protonmail.com")
}

Usage

  • In order to start a payment process only a single class is required.
private val paymentsOrchestrator: PaymentsOrchestrator
  • Calling register on PaymentsOrchestrator is mandatory with android context.
paymentsOrchestrator.register(context)
  • The most important function is the startBillingWorkflow. It can be used in 2 ways (with passing SessionId for account upgrade or passing null for SessionId for sign ups). Payments module does not deal with plans (display plans nor plan selection). Thus, this module should come after plan has been selected. PlanDetails which are mandatory should be passed to the startBillingWorkflow function.
data class PlanDetails(
    val id: String,
    val name: String,
    val subscriptionCycle: SubscriptionCycle,
    val amount: Long? = null,
    val currency: Currency = Currency.EUR
)

Note: amount is nullable, because final amount that will be billable to the user will be found out by the payments module, taking into account the existing subscriptions user have, coupons, credits etc.

paymentsOrchestrator.startBillingWorkFlow(
    sessionId = account.sessionId,
    selectedPlan = PlanDetails(
        "example of plan id",
        "Proton Plus",
        SubscriptionCycle.YEARLY
    ),
    codes = null
)

Client initiating the payment should expect the results as a callback onPaymentResult from paymentsOrchestrator:

onPaymentResult { result ->
    // do something with the payment result.
}

where the result is of type BillingResult:

data class BillingResult(
    val paySuccess: Boolean,
    val token: String?,
    val subscriptionCreated: Boolean
)