package com.example.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import android.util.Log;
import java.util.UUID;
import android.content.Intent;
import co.poynt.os.model.Intents;
import co.poynt.os.model.Payment;
import co.poynt.os.model.PaymentStatus;
public class MainActivity extends AppCompatActivity {
private static final String TAG = MainActivity.class.getSimpleName();
private static final int COLLECT_PAYMENT_REQUEST = 13132;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Do something in response to button click
//Button button = (Button) findViewById(R.id.button1);
//button.setText("Premuto");
Payment payment = new Payment();
String referenceId = UUID.randomUUID().toString();
payment.setReferenceId(referenceId);
payment.setAmount(10);
payment.setCurrency("EUR");
Intent collectPaymentIntent = new Intent(Intents.ACTION_COLLECT_PAYMENT);
collectPaymentIntent.putExtra(Intents.INTENT_EXTRAS_PAYMENT, payment);
startActivityForResult(collectPaymentIntent, COLLECT_PAYMENT_REQUEST);
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Check which request we're responding to
if (requestCode == COLLECT_PAYMENT_REQUEST) {
// Make sure the request was successful
if (resultCode == MainActivity.RESULT_OK) {
if (data != null) {
Payment payment = data.getParcelableExtra(Intents.INTENT_EXTRAS_PAYMENT);
Log.d(TAG, "Received onPaymentAction from PaymentFragment w/ Status("
+ payment.getStatus() + ")");
if (payment.getStatus().equals(PaymentStatus.COMPLETED)) {
Toast.makeText(this, "Payment Completed", Toast.LENGTH_LONG).show();
} else if (payment.getStatus().equals(PaymentStatus.AUTHORIZED)) {
Toast.makeText(this, "Payment Authorized", Toast.LENGTH_LONG).show();
} else if (payment.getStatus().equals(PaymentStatus.CANCELED)) {
Toast.makeText(this, "Payment Canceled", Toast.LENGTH_LONG).show();
} else if (payment.getStatus().equals(PaymentStatus.FAILED)) {
Toast.makeText(this, "Payment Failed", Toast.LENGTH_LONG).show();
} else if (payment.getStatus().equals(PaymentStatus.REFUNDED)) {
Toast.makeText(this, "Payment Refunded", Toast.LENGTH_LONG).show();
} else if (payment.getStatus().equals(PaymentStatus.VOIDED)) {
Toast.makeText(this, "Payment Voided", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Payment Completed", Toast.LENGTH_LONG).show();
}
}
} else if (resultCode == MainActivity.RESULT_CANCELED) {
Toast.makeText(this, "Payment Canceled", Toast.LENGTH_LONG).show();
}
}
}
}