Open Hakerjhom opened 3 weeks ago
dependencies { implementation 'com.paypal.sdk:paypal-android-sdk:2.16.0' } <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.paymentcheckoutapp">
<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>
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity">
<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
`dependencies { implementation 'com.paypal.sdk:paypal-android-sdk:2.16.0' } <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.paymentcheckoutapp">
<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>
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity">
<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
Teste