Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1205 from TUM-Dev/jacqueline/termsOfService
Browse files Browse the repository at this point in the history
Adds terms of service checkbox and link
  • Loading branch information
kordianbruck authored Nov 17, 2018
2 parents 5118b2b + 77283d8 commit c82681c
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ private void handleTicketReservationSuccess(TicketType ticketType,
Intent intent = new Intent(this, StripePaymentActivity.class);
intent.putExtra(Const.KEY_TICKET_PRICE, ticketType.getFormattedPrice());
intent.putExtra(Const.KEY_TICKET_HISTORY, response.getTicketHistory());
intent.putExtra(Const.KEY_TERMS_LINK, ticketType.getPaymentInfo().getTermsLink());
intent.putExtra(Const.KEY_STRIPE_API_PUBLISHABLE_KEY, ticketType.getPaymentInfo().getStripePublicKey());
startActivity(intent);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package de.tum.in.tumcampusapp.component.ui.ticket.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.transition.TransitionManager;
import android.view.View;
import android.view.autofill.AutofillManager;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.TextView;
Expand Down Expand Up @@ -49,6 +51,7 @@ public class StripePaymentActivity extends BaseActivity {
private EditText cardholderEditText;
private ViewSwitcher selectMethodSwitcher;
private MaterialButton purchaseButton;
private CheckBox termsOfServiceCheckBox;

private PaymentSession paymentSession;
private boolean didSelectPaymentMethod;
Expand All @@ -57,6 +60,8 @@ public class StripePaymentActivity extends BaseActivity {
// we need the ID to init the purchase

private String ticketPrice;
private String termsOfServiceLink;
private String stripePublishableKey;

public StripePaymentActivity() {
super(R.layout.activity_payment_stripe);
Expand All @@ -68,8 +73,13 @@ public void onCreate(Bundle savedInstanceState) {

ticketPrice = getIntent().getStringExtra(Const.KEY_TICKET_PRICE);
ticketHistory = getIntent().getIntExtra(Const.KEY_TICKET_HISTORY, -1);
termsOfServiceLink = getIntent().getStringExtra(Const.KEY_TERMS_LINK);
stripePublishableKey = getIntent().getStringExtra(Const.KEY_STRIPE_API_PUBLISHABLE_KEY);

if (ticketHistory < 0 || ticketPrice == null) {
if (ticketHistory < 0
|| ticketPrice == null
|| termsOfServiceLink.isEmpty()
|| stripePublishableKey == null) {
Utils.showToast(this, R.string.error_something_wrong);
finish();
return;
Expand Down Expand Up @@ -121,11 +131,22 @@ public void afterTextChanged(Editable s) {
purchaseButton = findViewById(R.id.complete_purchase_button);
purchaseButton.setText(purchaseButtonString);
purchaseButton.setOnClickListener(v -> purchaseTicket());

termsOfServiceCheckBox = findViewById(R.id.terms_of_service_checkbox);
termsOfServiceCheckBox.setOnClickListener((view) -> updateBuyButton());

findViewById(R.id.terms_of_service_button).setOnClickListener((view -> {
Intent browserIntent = new Intent(Intent.ACTION_VIEW);
browserIntent.setData(Uri.parse(termsOfServiceLink));
view.getContext().startActivity(browserIntent);
}));
}

private void updateBuyButton() {
boolean hasCardholder = !cardholderEditText.getText().toString().isEmpty();
boolean enabled = hasCardholder && didSelectPaymentMethod;
boolean enabled = hasCardholder
&& didSelectPaymentMethod
&& termsOfServiceCheckBox.isChecked();
float alpha = enabled ? 1.0f : 0.5f;

purchaseButton.setEnabled(enabled);
Expand Down Expand Up @@ -239,7 +260,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}

private void initStripeSession() {
PaymentConfiguration.init(Const.STRIPE_API_PUBLISHABLE_KEY);
PaymentConfiguration.init(stripePublishableKey);
initCustomerSession();
}

Expand Down Expand Up @@ -296,7 +317,7 @@ public void onError(int errorCode, @Nullable String errorMessage) {

@Override
public void onPaymentSessionDataChanged(@NonNull PaymentSessionData data) {
purchaseButton.setEnabled(true);
updateBuyButton();
selectMethodSwitcher.setEnabled(true);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package de.tum.`in`.tumcampusapp.component.ui.ticket.model

import com.google.gson.annotations.SerializedName

data class Payment(
@SerializedName("stripe_publishable_key")
var stripePublicKey: String = "",
@SerializedName("terms")
var termsLink: String = "",
var minTickets: Int = 1,
var maxTickets: Int = 1
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.tum.`in`.tumcampusapp.component.ui.ticket.model

import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.PrimaryKey
import androidx.room.RoomWarnings
import com.google.gson.annotations.SerializedName
Expand All @@ -20,7 +21,10 @@ data class TicketType(
@SerializedName("ticket_type")
var id: Int = 0,
var price: Int = 0,
var description: String = ""
var description: String = "",
@Ignore
@SerializedName("payment")
var paymentInfo: Payment = Payment()
) {

val formattedPrice: String
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/de/tum/in/tumcampusapp/utils/Const.kt
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,13 @@ object Const {
const val CALENDAR_FILTER_HOUR_LIMIT_MIN_DEFAULT = "8"
const val CALENDAR_FILTER_HOUR_LIMIT_MAX_DEFAULT = "20"

const val STRIPE_API_PUBLISHABLE_KEY = "pk_live_bjSAhBM3WFUqeNI4cJn9upDW"
const val KEY_STRIPE_API_PUBLISHABLE_KEY = "stripeApiPublishableKey"
const val KEY_EVENT = "event"
const val KEY_EVENT_ID = "eventId"
const val KEY_CARD_HOLDER = "cardholder"
const val KEY_TICKET_PRICE = "ticketPrice"
const val KEY_TICKET_HISTORY = "ticketHistory"
const val KEY_TERMS_LINK = "termsOfServiceLink"

const val SHOW_DRAWER = "showDrawer"

Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_external_link.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:autoMirrored="true"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/white"
android:pathData="M5,3C3.9069,3 3,3.9069 3,5L3,19C3,20.0931 3.9069,21 5,21L19,21C20.0931,21 21,20.0931 21,19L21,12L19,12L19,19L5,19L5,5L12,5L12,3L5,3zM14,3L14,5L17.5859,5L8.293,14.293L9.707,15.707L19,6.4141L19,10L21,10L21,3L14,3z" />
</vector>
27 changes: 27 additions & 0 deletions app/src/main/res/layout/activity_payment_stripe.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,33 @@
android:layout_height="0dp"
android:layout_weight="1" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/material_small_padding"
android:layout_marginEnd="@dimen/material_default_padding"
android:gravity="center_vertical"
android:orientation="horizontal">

<CheckBox
android:id="@+id/terms_of_service_checkbox"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/stripe_terms_of_service_checkbox" />

<com.google.android.material.button.MaterialButton
android:id="@+id/terms_of_service_button"
style="@style/Widget.MaterialComponents.Button.OutlinedButton.Icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/material_small_padding"
android:text="@string/stripe_terms_of_service_button"
android:textAllCaps="false"
app:cornerRadius="@dimen/material_corner_radius"
app:icon="@drawable/ic_external_link" />
</LinearLayout>

<com.google.android.material.button.MaterialButton
android:id="@+id/complete_purchase_button"
style="@style/Widget.MaterialComponents.Button"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -651,5 +651,7 @@ Signatur: %5$s</string>
<string name="employee_mode_info">Menüpunkte wie die Notenansicht oder Studienbeitrag werden in dieser Ansicht nicht angezeigt.</string>
<string name="event_imminent_error">Tickets können nur bis zu vier Stunden vor Beginn über die App erworben werden.</string>
<string name="show_in_calendar">Im Kalender öffnen</string>
<string name="stripe_terms_of_service_checkbox">Ich stimme den allgemeinen Geschäftsbedingungen (AGB) zu.</string>
<string name="stripe_terms_of_service_button">AGB</string>
<string name="tickets_available_here">Tickets hier erhältlich!</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -705,5 +705,8 @@ Signature: %5$s</string>
<string name="next_lecture_hide">Hide</string>
<string name="next_lecture_show_more">Show %d more …</string>
<string name="show_in_calendar">Show in Calendar</string>

<string name="stripe_terms_of_service_checkbox">I agree to the terms of service.</string>
<string name="stripe_terms_of_service_button">Terms of Service</string>
<string name="tickets_available_here">Tickets available here!</string>
</resources>

0 comments on commit c82681c

Please sign in to comment.