Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Foto #1

Open
Hakerjhom opened this issue Jun 30, 2024 · 3 comments
Open

Foto #1

Hakerjhom opened this issue Jun 30, 2024 · 3 comments

Comments

@Hakerjhom
Copy link
Owner

Teste

@Hakerjhom
Copy link
Owner Author

Hakerjhom commented Jun 30, 2024

dependencies {
implementation 'com.paypal.sdk:paypal-android-sdk:2.16.0'
}

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.PaymentCheckoutApp">
    
    <!-- PayPal SDK Meta-Data -->
    <meta-data
        android:name="com.paypal.sdk.APPLICATION_ID"
        android:value="YOUR_PAYPAL_CLIENT_ID" />

    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
<Button
    android:id="@+id/btnPayNow"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Pay Now"
    android:layout_centerInParent="true" />
package com.example.paymentcheckoutapp;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;

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;

public class MainActivity extends AppCompatActivity {

private static final int PAYPAL_REQUEST_CODE = 123;
private static PayPalConfiguration config = new PayPalConfiguration()
        .environment(PayPalConfiguration.ENVIRONMENT_SANDBOX)
        .clientId("YOUR_PAYPAL_CLIENT_ID");

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Intent intent = new Intent(this, PayPalService.class);
    intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
    startService(intent);

    Button btnPayNow = findViewById(R.id.btnPayNow);
    btnPayNow.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            processPayment();
        }
    });
}

private void processPayment() {
    PayPalPayment payment = new PayPalPayment(new BigDecimal("10"), "USD",
            "Test Payment", PayPalPayment.PAYMENT_INTENT_SALE);

    Intent intent = new Intent(this, PaymentActivity.class);
    intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
    intent.putExtra(PaymentActivity.EXTRA_PAYMENT, payment);
    startActivityForResult(intent, PAYPAL_REQUEST_CODE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == PAYPAL_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
            if (confirm != null) {
                try {
                    Log.i("paymentExample", confirm.toJSONObject().toString(4));
                } catch (JSONException e) {
                    Log.e("paymentExample", "an extremely unlikely failure occurred: ", e);
                }
            }
        } else if (resultCode == 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.");
        }
    }
}

@Override
public void onDestroy() {
    stopService(new Intent(this, PayPalService.class));
    super.onDestroy();
}

}package com.example.paymentcheckoutapp

import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.paypal.android.sdk.payments.*
import kotlinx.android.synthetic.main.activity_main.*
import org.json.JSONException
import java.math.BigDecimal

class MainActivity : AppCompatActivity() {

companion object {
    const val PAYPAL_REQUEST_CODE = 123
    val config = PayPalConfiguration()
        .environment(PayPalConfiguration.ENVIRONMENT_SANDBOX)
        .clientId("YOUR_PAYPAL_CLIENT_ID")
}

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    val intent = Intent(this, PayPalService::class.java)
    intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config)
    startService(intent)

    btnPayNow.setOnClickListener {
        processPayment()
    }
}

private fun processPayment() {
    val payment = PayPalPayment(BigDecimal("10"), "USD", "Test Payment",
        PayPalPayment.PAYMENT_INTENT_SALE)

    val intent = Intent(this, PaymentActivity::class.java)
    intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config)
    intent.putExtra(PaymentActivity.EXTRA_PAYMENT, payment)
    startActivityForResult(intent, PAYPAL_REQUEST_CODE)
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)

    if (requestCode == PAYPAL_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            val confirm = data?.getParcelableExtra<PaymentConfirmation>(PaymentActivity.EXTRA_RESULT_CONFIRMATION)
            confirm?.let {
                try {
                    Log.i("paymentExample", it.toJSONObject().toString(4))
                } catch (e: JSONException) {
                    Log.e("paymentExample", "an extremely unlikely failure occurred: ", e)
                }
            }
        } else if (resultCode == 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.")
        }
    }
}

override fun onDestroy() {
    stopService

@Hakerjhom Hakerjhom mentioned this issue Jun 30, 2024
@Hakerjhom
Copy link
Owner Author

#1 (comment)

@Hakerjhom
Copy link
Owner Author

`dependencies {
implementation 'com.paypal.sdk:paypal-android-sdk:2.16.0'
}

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.PaymentCheckoutApp">
    
    <!-- PayPal SDK Meta-Data -->
    <meta-data
        android:name="com.paypal.sdk.APPLICATION_ID"
        android:value="YOUR_PAYPAL_CLIENT_ID" />

    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
<Button
    android:id="@+id/btnPayNow"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Pay Now"
    android:layout_centerInParent="true" />
package com.example.paymentcheckoutapp;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;

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;

public class MainActivity extends AppCompatActivity {

private static final int PAYPAL_REQUEST_CODE = 123;
private static PayPalConfiguration config = new PayPalConfiguration()
        .environment(PayPalConfiguration.ENVIRONMENT_SANDBOX)
        .clientId("YOUR_PAYPAL_CLIENT_ID");

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Intent intent = new Intent(this, PayPalService.class);
    intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
    startService(intent);

    Button btnPayNow = findViewById(R.id.btnPayNow);
    btnPayNow.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            processPayment();
        }
    });
}

private void processPayment() {
    PayPalPayment payment = new PayPalPayment(new BigDecimal("10"), "USD",
            "Test Payment", PayPalPayment.PAYMENT_INTENT_SALE);

    Intent intent = new Intent(this, PaymentActivity.class);
    intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
    intent.putExtra(PaymentActivity.EXTRA_PAYMENT, payment);
    startActivityForResult(intent, PAYPAL_REQUEST_CODE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == PAYPAL_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
            if (confirm != null) {
                try {
                    Log.i("paymentExample", confirm.toJSONObject().toString(4));
                } catch (JSONException e) {
                    Log.e("paymentExample", "an extremely unlikely failure occurred: ", e);
                }
            }
        } else if (resultCode == 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.");
        }
    }
}

@Override
public void onDestroy() {
    stopService(new Intent(this, PayPalService.class));
    super.onDestroy();
}

}
package com.example.paymentcheckoutapp

import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.paypal.android.sdk.payments.*
import kotlinx.android.synthetic.main.activity_main.*
import org.json.JSONException
import java.math.BigDecimal

class MainActivity : AppCompatActivity() {

companion object {
    const val PAYPAL_REQUEST_CODE = 123
    val config = PayPalConfiguration()
        .environment(PayPalConfiguration.ENVIRONMENT_SANDBOX)
        .clientId("YOUR_PAYPAL_CLIENT_ID")
}

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    val intent = Intent(this, PayPalService::class.java)
    intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config)
    startService(intent)

    btnPayNow.setOnClickListener {
        processPayment()
    }
}

private fun processPayment() {
    val payment = PayPalPayment(BigDecimal("10"), "USD", "Test Payment",
        PayPalPayment.PAYMENT_INTENT_SALE)

    val intent = Intent(this, PaymentActivity::class.java)
    intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config)
    intent.putExtra(PaymentActivity.EXTRA_PAYMENT, payment)
    startActivityForResult(intent, PAYPAL_REQUEST_CODE)
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)

    if (requestCode == PAYPAL_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            val confirm = data?.getParcelableExtra<PaymentConfirmation>(PaymentActivity.EXTRA_RESULT_CONFIRMATION)
            confirm?.let {
                try {
                    Log.i("paymentExample", it.toJSONObject().toString(4))
                } catch (e: JSONException) {
                    Log.e("paymentExample", "an extremely unlikely failure occurred: ", e)
                }
            }
        } else if (resultCode == 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.")
        }
    }
}

override fun onDestroy() {
    stopService

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant