Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
New design
Browse files Browse the repository at this point in the history
  • Loading branch information
a.ignatov committed Jun 8, 2023
1 parent bddef16 commit c776762
Show file tree
Hide file tree
Showing 78 changed files with 1,154 additions and 737 deletions.
127 changes: 67 additions & 60 deletions app/src/main/java/ru/cloudpayments/demo/screens/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import ru.cloudpayments.sdk.configuration.CloudpaymentsSDK
import ru.cloudpayments.sdk.configuration.PaymentConfiguration
import ru.cloudpayments.sdk.configuration.PaymentData


class MainActivity : BaseActivity() {

private val cpSdkLauncher = CloudpaymentsSDK.getInstance().launcher(this, result = {
Expand Down Expand Up @@ -39,66 +38,74 @@ class MainActivity : BaseActivity() {
val view = binding.root
setContentView(view)

binding.buttonRun.setOnClickListener {
binding.buttonRunTop.setOnClickListener {
runCpSdk()
}

val apiUrl = binding.editApiUrl.text.toString()
val publicId = binding.editPublicId.text.toString()
val amount = binding.editAmount.text.toString()
val currency = binding.editCurrency.text.toString()
val invoiceId = binding.editInvoiceId.text.toString()
val description = binding.editDescription.text.toString()
val accountId = binding.editAccountId.text.toString()
val email = binding.editEmail.text.toString()

val payerFirstName = binding.editPayerFirstName.text.toString()
val payerLastName = binding.editPayerLastName.text.toString()
val payerMiddleName = binding.editPayerMiddleName.text.toString()
val payerBirthDay = binding.editPayerBirth.text.toString()
val payerAddress = binding.editPayerAddress.text.toString()
val payerStreet = binding.editPayerStreet.text.toString()
val payerCity = binding.editPayerCity.text.toString()
val payerCountry = binding.editPayerCountry.text.toString()
val payerPhone = binding.editPayerPhone.text.toString()
val payerPostcode = binding.editPayerPostcode.text.toString()

val jsonData = binding.editJsonData.text.toString()
val isDualMessagePayment = binding.checkboxDualMessagePayment.isChecked

var payer = PaymentDataPayer()
payer.firstName = payerFirstName
payer.lastName = payerLastName
payer.middleName = payerMiddleName
payer.birthDay = payerBirthDay
payer.address = payerAddress
payer.street = payerStreet
payer.city = payerCity
payer.country = payerCountry
payer.phone = payerPhone
payer.postcode = payerPostcode

val paymentData = PaymentData(
amount = amount,
currency = currency,
invoiceId = invoiceId,
description = description,
accountId = accountId,
email = email,
payer = payer,
jsonData = jsonData
)

val configuration = PaymentConfiguration(
publicId = publicId,
paymentData = paymentData,
scanner = CardIOScanner(),
showEmailField = true,
useDualMessagePayment = isDualMessagePayment,
disableGPay = false,
disableYandexPay = false,
yandexPayMerchantID = "1423423564546767575",
apiUrl = apiUrl
)
cpSdkLauncher.launch(configuration)
binding.buttonRun.setOnClickListener {
runCpSdk()
}
}

private fun runCpSdk() {

val apiUrl = binding.editApiUrl.text.toString()
val publicId = binding.editPublicId.text.toString()
val amount = binding.editAmount.text.toString()
val currency = binding.editCurrency.text.toString()
val invoiceId = binding.editInvoiceId.text.toString()
val description = binding.editDescription.text.toString()
val accountId = binding.editAccountId.text.toString()
val email = binding.editEmail.text.toString()

val payerFirstName = binding.editPayerFirstName.text.toString()
val payerLastName = binding.editPayerLastName.text.toString()
val payerMiddleName = binding.editPayerMiddleName.text.toString()
val payerBirthDay = binding.editPayerBirth.text.toString()
val payerAddress = binding.editPayerAddress.text.toString()
val payerStreet = binding.editPayerStreet.text.toString()
val payerCity = binding.editPayerCity.text.toString()
val payerCountry = binding.editPayerCountry.text.toString()
val payerPhone = binding.editPayerPhone.text.toString()
val payerPostcode = binding.editPayerPostcode.text.toString()

val jsonData = binding.editJsonData.text.toString()
val isDualMessagePayment = binding.checkboxDualMessagePayment.isChecked

var payer = PaymentDataPayer()
payer.firstName = payerFirstName
payer.lastName = payerLastName
payer.middleName = payerMiddleName
payer.birthDay = payerBirthDay
payer.address = payerAddress
payer.street = payerStreet
payer.city = payerCity
payer.country = payerCountry
payer.phone = payerPhone
payer.postcode = payerPostcode

val paymentData = PaymentData(
amount = amount,
currency = currency,
invoiceId = invoiceId,
description = description,
accountId = accountId,
email = email,
payer = payer,
jsonData = jsonData
)

val configuration = PaymentConfiguration(
publicId = publicId,
paymentData = paymentData,
scanner = CardIOScanner(),
requireEmail = false,
useDualMessagePayment = isDualMessagePayment,
disableGPay = false,
disableYandexPay = false,
yandexPayMerchantID = "",
apiUrl = apiUrl
)
cpSdkLauncher.launch(configuration)
}
}
3 changes: 1 addition & 2 deletions app/src/main/res/layout/activity_checkout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@
android:layout_marginTop="@dimen/ui_margin_16dp"
android:layout_marginRight="@dimen/ui_margin_16dp"
android:text="@string/checkout_payment"
app:backgroundTint="@color/colorAccent"
style="@style/cpsdk_UnelevatedButton"/>
app:backgroundTint="@color/colorAccent"/>

<TextView
android:layout_width="match_parent"
Expand Down
23 changes: 20 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
xmlns:app="http://schemas.android.com/apk/res-auto">
android:background="@android:color/white">

<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
Expand All @@ -20,6 +20,23 @@
android:layout_height="wrap_content"
android:src="@drawable/logo" />

<Button
android:id="@+id/button_run_top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/ui_margin_16dp"
android:text="RUN"/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:gravity="center"
android:textColor="@android:color/black"
android:textStyle="bold"
android:textSize="24sp"
android:text="Settings:"/>

<TextView
style="@style/CPETextView"
android:text="API URL (only for testing):"/>
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
kotlin.code.style=official
org.gradle.unsafe.configuration-cache = true
47 changes: 17 additions & 30 deletions sdk/src/main/java/ru/cloudpayments/sdk/card/Card.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package ru.cloudpayments.sdk.card

import android.text.TextUtils
import android.util.Base64
import android.util.Log
import java.io.UnsupportedEncodingException
import java.security.*
import java.security.InvalidKeyException
import java.security.KeyFactory
import java.security.NoSuchAlgorithmException
import java.security.PublicKey
import java.security.SecureRandom
import java.security.spec.InvalidKeySpecException
import java.security.spec.X509EncodedKeySpec
import java.text.DateFormat
import java.text.ParseException
import java.text.SimpleDateFormat
import java.util.*
import javax.crypto.BadPaddingException
import javax.crypto.Cipher
import javax.crypto.IllegalBlockSizeException
Expand All @@ -36,36 +35,24 @@ class Card {
false
} else {
val number = prepareCardNumber(cardNumber)
return if (TextUtils.isEmpty(number) || number.length < 14) {
return if (TextUtils.isEmpty(number) || number.length < 14 || number.length > 19 ) {
false
} else {
var sum = 0
if (number.length % 2 == 0) {
for (i in number.indices step 2) {
var c = number.substring(i, i + 1).toInt()
c *= 2
if (c > 9) {
c -= 9
}
sum += c
sum += number.substring(i + 1, i + 2).toInt()
}
} else {
for (i in 1 until number.length step 2) {
var c: Int = number.substring(i, i + 1).toInt()
c *= 2
if (c > 9) {
c -= 9
}
sum += c
sum += number.substring(i - 1, i).toInt()
}
}
sum % 10 == 0
number.luhnAlgorithm()
}
}
}

fun String.luhnAlgorithm() = reversed()
.map(Character::getNumericValue)
.mapIndexed { index, digit ->
when {
index % 2 == 0 -> digit
digit < 5 -> digit * 2
else -> digit * 2 - 9
}
}.sum() % 10 == 0

fun isValidExpDate(exp: String?): Boolean {
return if (exp == null) {
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ru.cloudpayments.sdk.scanner.CardScanner
data class PaymentConfiguration(val publicId: String,
val paymentData: PaymentData,
val scanner: CardScanner?,
val showEmailField: Boolean = false,
val requireEmail: Boolean = false,
val useDualMessagePayment: Boolean = false,
val disableGPay: Boolean = false,
val disableYandexPay: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ class PaymentData(val amount: String,
val invoiceId: String? = null,
val description: String? = null,
val accountId: String? = null,
val email: String? = null,
var email: String? = null,
val payer: PaymentDataPayer? = null,
val jsonData: String? = null): Parcelable
Loading

0 comments on commit c776762

Please sign in to comment.