google-pay / react-native-make-payment Goto Github PK
View Code? Open in Web Editor NEWReact Native library for making native payments
License: Apache License 2.0
React Native library for making native payments
License: Apache License 2.0
import { PaymentRequest as Gpay } from "@google/react-native-make-payment";
const paymentDetails = {
total: {
amount: {
currency: "USD",
value: "14.95",
},
},
};
const googlePayRequest = {
apiVersion: 2,
apiVersionMinor: 0,
allowedPaymentMethods: [
{
type: "CARD",
parameters: {
allowedAuthMethods: ["PAN_ONLY", "CRYPTOGRAM_3DS"],
allowedCardNetworks: ["AMEX", "DISCOVER", "JCB", "MASTERCARD", "VISA"],
},
tokenizationSpecification: {
type: "PAYMENT_GATEWAY",
parameters: {
gateway: "stripe",
"stripe:version": "2018-10-31",
"stripe:publishableKey":
"myPublishertestkey",
},
},
},
],
merchantInfo: {
// merchantId: "01234567890123456789",
merchantId: "",
merchantName: "",
},
transactionInfo: {
totalPriceStatus: "FINAL",
totalPrice: paymentDetails.total.amount.value,
currencyCode: paymentDetails.total.amount.currency,
countryCode: "US",
},
};
const paymentMethods = [
{
supportedMethods: "google_pay",
data: googlePayRequest,
},
];
const GooglePay = new Gpay(paymentMethods, paymentDetails);
function showPaymentForm() {
try {
GooglePay.show()
.then((response) => {
if (response === null) {
console.log("Payment sheet cancelled");
} else {
console.log("REsponse", JSON.stringify(response));
}
})
.catch((error) => {
console.log(paymentRequest.show() error: ${error}
);
});
} catch (err) {
console.log("final error", err);
}
}
const { AndroidConfig, withAndroidManifest } = require("@expo/config-plugins");
const { addMetaDataItemToMainApplication, getMainApplicationOrThrow } =
AndroidConfig.Manifest;
/**
* Adds the following to AndroidManifest.xml:
*
* <application>
* ...
* <meta-data
* android:name="com.google.android.gms.wallet.api.enabled"
* android:value="true|false" />
* </application>
*/
function setGooglePayMetaData(modResults) {
const GOOGLE_PAY_META_NAME = "com.google.android.gms.wallet.api.enabled";
const mainApplication = getMainApplicationOrThrow(modResults);
addMetaDataItemToMainApplication(
mainApplication,
GOOGLE_PAY_META_NAME,
"true",
);
return modResults;
}
function withGooglePayAndroid(expoConfig) {
return withAndroidManifest(expoConfig, (config) => {
config.modResults = setGooglePayMetaData(config.modResults);
return config;
});
}
module.exports = function withGooglePay(config, props) {
config = withGooglePayAndroid(config, props);
return config;
};
Hi, I have added this package in expo app for react native. For android this works perfectly but once I run app on iOS, I was getting this error. cannot find getConstants() of null
.
Can you tell me what should I do to get rid of this error on iOS?
Thank you.
Hi, in the example we can see that the button has several arguments, such as radius
, type
and theme
. But in native code, these arguments are ignored, instead default values are used.
var type = ButtonConstants.ButtonType.BUY
var theme = ButtonConstants.ButtonTheme.DARK
var cornerRadius = 10
I'm unable to see the transaction details in my response although the tokenization data and payment method everything is there in response but not the transaction details
When following the instructions for working with Google Pay, you'll need to initialize a payment request instance as follows:
const paymentRequest = new PaymentRequest(paymentMethods, paymentDetails);
which includes payment details which are unique for each payment.
This initialization includes payment details that are unique to each payment transaction. However, when attempting to create a new instance with updated payment details, you may encounter the following issue:
**Possible Unhandled Promise Rejection (id: 0):
Error: You attempted to set the key `softwareInfo` with the value `{"id":"react-native-make-payment","version":"0.1.0"}` on an object that is meant to be immutable and has been frozen.
Error: You attempted to set the key `softwareInfo` with the value `{"id":"react-native-make-payment","version":"0.1.0"}` on an object that is meant to be immutable and has been frozen.**
I kindly request your assistance in resolving this issue or providing instructions on how to bypass it.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.