Skip to content

Commit

Permalink
Pagamento
Browse files Browse the repository at this point in the history
  • Loading branch information
luizcz committed Aug 10, 2017
1 parent 09b39c2 commit 2b805c4
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dependencies {
compile 'com.google.maps.android:android-maps-utils:0.3+'
compile 'com.google.android.gms:play-services:10.0.1'
compile 'com.github.brnunes:swipeablerecyclerview:1.0.2'
compile 'com.paypal.sdk:paypal-android-sdk:2.15.3'

}
configurations
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="projetoum.equipe.iteach">

<uses-permission android:name="android.permission.INTERNET" />
Expand All @@ -11,6 +12,7 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-sdk android:minSdkVersion="15" tools:overrideLibrary="com.paypal.android.sdk.payments, io.card.payment"/>

<application
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package projetoum.equipe.iteach.activities;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
Expand All @@ -24,7 +25,15 @@
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.paypal.android.sdk.payments.PayPalConfiguration;
import com.paypal.android.sdk.payments.PayPalPayment;
import com.paypal.android.sdk.payments.PayPalService;
import com.paypal.android.sdk.payments.PaymentActivity;
import com.paypal.android.sdk.payments.PaymentConfirmation;

import org.json.JSONException;

import java.math.BigDecimal;
import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -61,6 +70,7 @@ public class VisualizarAulaActivity extends DrawerActivity implements OnMapReady
private Button remover;
private Date dataHoje;
private Date dataFim;
private static PayPalConfiguration config = new PayPalConfiguration();

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -73,6 +83,16 @@ protected void onCreate(Bundle savedInstanceState) {
(SupportMapFragment) getSupportFragmentManager().findFragmentById(aula_mapa);
mapFragment.getMapAsync(this);

config.environment(PayPalConfiguration.ENVIRONMENT_SANDBOX)

.clientId("YOUR_CLIENT_ID_HERE");

Intent intent = new Intent(this, PayPalService.class);

intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);

startService(intent);


AlertDialog.Builder builder = new AlertDialog.Builder(this, android.R.style.Theme_Material_Dialog_Alert);

Expand Down Expand Up @@ -127,6 +147,17 @@ public void execute(Integer result) {
});
participar.setVisibility(View.GONE);
deixar.setVisibility(View.VISIBLE);
PayPalPayment payment = new PayPalPayment(new BigDecimal(aula.getValue().toString()), "BRL", aula.getName(),
PayPalPayment.PAYMENT_INTENT_SALE);

Intent intent = new Intent(getApplicationContext(), PaymentActivity.class);

// send the same configuration for restart resiliency
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);

intent.putExtra(PaymentActivity.EXTRA_PAYMENT, payment);

startActivityForResult(intent, 0);
}
}
});
Expand Down Expand Up @@ -487,4 +518,33 @@ protected void onPostExecute(Bitmap bitmap) {
}
}.execute();
}


@Override
public void onDestroy() {
stopService(new Intent(this, PayPalService.class));
super.onDestroy();
}
@Override
protected void onActivityResult (int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
if (confirm != null) {
try {
Log.i("paymentExample", confirm.toJSONObject().toString(4));
// TODO: send 'confirm' to your server for verification.
// see https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/
// for more details.
} catch (JSONException e) {
Log.e("paymentExample", "an extremely unlikely failure occurred: ", e);
}
}
}
else if (resultCode == Activity.RESULT_CANCELED) {
Log.i("paymentExample", "The user canceled.");
}
else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
Log.i("paymentExample", "An invalid Payment or PayPalConfiguration was submitted. Please see the docs.");
}
}
}

0 comments on commit 2b805c4

Please sign in to comment.