Skip to content

Commit

Permalink
Release 1.36.1
Browse files Browse the repository at this point in the history
  • Loading branch information
CheZhongSdk committed Jan 19, 2023
1 parent 5795155 commit a66ff2f
Show file tree
Hide file tree
Showing 15 changed files with 435 additions and 155 deletions.
10 changes: 5 additions & 5 deletions Examples/Example-Java/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ android {
}

dependencies {
implementation 'com.izettle.payments:android-sdk-ui:1.34.3'
implementation 'com.izettle.payments:android-sdk-ui:1.36.1'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.3.0-alpha01'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.lifecycle:lifecycle-process:2.2.0'
implementation 'androidx.lifecycle:lifecycle-process:2.5.1'
}
7 changes: 5 additions & 2 deletions Examples/Example-Java/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,23 @@
android:theme="@style/AppTheme"
tools:replace="android:fullBackupContent,android:supportsRtl">

<activity android:name=".MainActivity"
<activity android:name=".StartActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".MainActivity" />

<activity
android:name=".CardReaderActivity"
android:label="Card Reader" />

<activity
android:name="com.izettle.payments.android.java_example.PayPalQrcActivity"
android:name=".PayPalQrcActivity"
android:label="PayPal Qrc" />

<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.content.Intent;
import android.os.Bundle;
import android.text.SpannableStringBuilder;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
Expand All @@ -16,6 +17,7 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.MutableLiveData;

import com.google.android.material.snackbar.Snackbar;
import com.izettle.payments.android.payment.TransactionReference;
import com.izettle.payments.android.payment.refunds.CardPaymentPayload;
import com.izettle.payments.android.payment.refunds.RefundsManager;
Expand All @@ -34,9 +36,9 @@ public class CardReaderActivity extends AppCompatActivity {

private Button chargeButton;
private Button refundButton;
private EditText refundAmountEditText;
private Button settingsButton;
private EditText amountEditText;
private EditText refundAmountEditText;
private CheckBox tippingCheckBox;
private CheckBox installmentsCheckBox;
private CheckBox loginCheckBox;
Expand All @@ -58,47 +60,44 @@ public void onCreate(Bundle savedInstanceState) {

lastPaymentTraceId.observe(this, value -> refundButton.setEnabled(value != null));

chargeButton.setOnClickListener( v -> onChargeClicked());
refundButton.setOnClickListener( v -> onRefundClicked());
settingsButton.setOnClickListener( v -> onSettingsClicked());
chargeButton.setOnClickListener(v -> onChargeClicked());
refundButton.setOnClickListener(v -> onRefundClicked());
settingsButton.setOnClickListener(v -> onSettingsClicked());
}

private final ActivityResultLauncher<Intent> paymentLauncher = registerForActivityResult(new StartActivityForResult(), result -> {
if (result.getResultCode() == Activity.RESULT_OK && result.getData() != null) {
CardPaymentResult parsed = result.getData().getParcelableExtra(CardPaymentActivity.RESULT_EXTRA_PAYLOAD);
if(parsed instanceof CardPaymentResult.Completed) {
showToast("Payment completed");
if (parsed instanceof CardPaymentResult.Completed) {
showSnackBar("Payment completed");
CardPaymentResult.Completed casted = (CardPaymentResult.Completed) parsed;
lastPaymentTraceId.setValue(Objects.requireNonNull(casted.getPayload().getReference()).getId());
refundAmountEditText.setText(new SpannableStringBuilder()
.append(String.valueOf(casted.getPayload().getAmount())));
}
else if(parsed instanceof CardPaymentResult.Failed) {
showToast("Payment failed "+ ((CardPaymentResult.Failed) parsed).getReason());
}
else if(parsed instanceof CardPaymentResult.Canceled) {
showToast("Payment canceled");
} else if (parsed instanceof CardPaymentResult.Failed) {
showSnackBar("Payment failed " + ((CardPaymentResult.Failed) parsed).getReason());
} else if (parsed instanceof CardPaymentResult.Canceled) {
showSnackBar("Payment canceled");
}
}
});

private final ActivityResultLauncher<Intent> refundLauncher = registerForActivityResult(new StartActivityForResult(), result -> {
if (result.getResultCode() == Activity.RESULT_OK && result.getData() != null) {
RefundResult parsed = result.getData().getParcelableExtra(RefundsActivity.RESULT_EXTRA_PAYLOAD);
if(parsed instanceof RefundResult.Completed) {
showToast("Refund completed");
}
else if(parsed instanceof RefundResult.Failed) {
showToast("Refund failed "+ ((RefundResult.Failed) parsed).getReason());
}
else if(parsed instanceof RefundResult.Canceled) {
showToast("Refund canceled");
if (parsed instanceof RefundResult.Completed) {
showSnackBar("Refund completed");
} else if (parsed instanceof RefundResult.Failed) {
showSnackBar("Refund failed " + ((RefundResult.Failed) parsed).getReason());
} else if (parsed instanceof RefundResult.Canceled) {
showSnackBar("Refund canceled");
}
}
});

private void showToast(String text) {
Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
private void showSnackBar(String text) {
ViewGroup viewGroup = findViewById(android.R.id.content);
Snackbar.make(viewGroup.getChildAt(0), text, Snackbar.LENGTH_LONG).show();
}

private void onChargeClicked() {
Expand All @@ -112,16 +111,16 @@ private void onChargeClicked() {
boolean enableInstallments = installmentsCheckBox.isChecked();
boolean enableLogin = loginCheckBox.isChecked();
TransactionReference reference = new TransactionReference.Builder(internalTraceId)
.put("PAYMENT_EXTRA_INFO", "Started from home screen")
.build();
.put("PAYMENT_EXTRA_INFO", "Started from home screen")
.build();

Intent intent = new CardPaymentActivity.IntentBuilder(this)
.amount(amount)
.reference(reference)
.enableInstalments(enableInstallments)
.enableTipping(enableTipping)
.enableLogin(enableLogin)
.build();
.amount(amount)
.reference(reference)
.enableInstalments(enableInstallments)
.enableTipping(enableTipping)
.enableLogin(enableLogin)
.build();

paymentLauncher.launch(intent);
}
Expand All @@ -131,11 +130,19 @@ private void onSettingsClicked() {
}

private void onRefundClicked() {
String id = lastPaymentTraceId.getValue();
if(id != null) {
Long amount = parseLong(refundAmountEditText.getText());
IZettleSDK.Instance.getRefundsManager().retrieveCardPayment(id, new RefundCallback(amount));
String internalTraceId = lastPaymentTraceId.getValue();
boolean isDevMode = ((MainApplication) getApplication()).isDevMode();

if (internalTraceId == null && !isDevMode) {
showSnackBar("No payment taken");
return;
}

Long amount = parseLong(refundAmountEditText.getText());
IZettleSDK.Instance.getRefundsManager().retrieveCardPayment(
(internalTraceId != null ? internalTraceId : ""),
new RefundCallback(amount)
);
}

private class RefundCallback implements RefundsManager.Callback<CardPaymentPayload, RetrieveCardPaymentFailureReason> {
Expand All @@ -148,21 +155,21 @@ public RefundCallback(Long amount) {

@Override
public void onFailure(RetrieveCardPaymentFailureReason reason) {
showToast("Refund failed");
showSnackBar("Refund failed");
}

@Override
public void onSuccess(CardPaymentPayload payload) {
TransactionReference reference = new TransactionReference.Builder(UUID.randomUUID().toString())
.put("REFUND_EXTRA_INFO", "Started from home screen")
.build();
.put("REFUND_EXTRA_INFO", "Started from home screen")
.build();
Intent intent = new RefundsActivity.IntentBuilder(CardReaderActivity.this)
.cardPayment(payload)
.receiptNumber("#123456")
.taxAmount(amount)
.refundAmount(amount)
.reference(reference)
.build();
.cardPayment(payload)
.receiptNumber("#123456")
.taxAmount(amount)
.refundAmount(amount)
.reference(reference)
.build();

refundLauncher.launch(intent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,28 @@

public class MainApplication extends MultiDexApplication {

@Override
public void onCreate() {
super.onCreate();
initIZettleSDK();
private boolean started = false;
private boolean isDevMode = false;

public boolean isStarted() {
return started;
}

public boolean isDevMode() {
return isDevMode;
}

private void initIZettleSDK() {
public void initIZettleSDK(boolean devMode) {
if (started) return;
started = true;
isDevMode = devMode;

String clientId = getString(R.string.client_id);
String scheme = getString(R.string.redirect_url_scheme);
String host = getString(R.string.redirect_url_host);
String redirectUrl = scheme + "://" + host;
IZettleSDK.Instance.init(this, clientId, redirectUrl);
IZettleSDK.Instance.init(this, clientId, redirectUrl, isDevMode);
ProcessLifecycleOwner.get().getLifecycle().addObserver(new SdkLifecycle(IZettleSDK.Instance));
}

}
Loading

0 comments on commit a66ff2f

Please sign in to comment.