@google/react-native-make-payment
Version:
React Native library for making native payments
66 lines (64 loc) • 2.37 kB
JavaScript
var _react = _interopRequireDefault(require("react"));
var _reactNative = require("react-native");
var _GooglePayButton = require("./GooglePayButton");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*
* Copyright 2024 Google LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const MakePayment = _reactNative.NativeModules.MakePayment;
const GOOGLE_PAY_PMI = 'google_pay';
class PaymentRequest {
#name = '@google/react-native-make-payment';
#version = '0.1.2';
constructor(paymentMethods, paymentDetails) {
this.paymentMethods = Object.fromEntries(paymentMethods.map(pm => [pm.supportedMethods, pm.data]));
this.paymentDetails = paymentDetails;
try {
const pkg = require('../package.json');
this.#name = pkg.name;
this.#version = pkg.version;
} catch (_) {}
if (this.paymentMethods[GOOGLE_PAY_PMI] && !this.paymentMethods[GOOGLE_PAY_PMI].merchantInfo.softwareInfo) {
this.paymentMethods[GOOGLE_PAY_PMI].merchantInfo.softwareInfo = {
id: this.#name.split('/').pop(),
version: this.#version
};
}
}
canMakePayment() {
return _reactNative.Platform.select({
android: () => MakePayment.isReadyToPay(this.paymentMethods[GOOGLE_PAY_PMI]),
default: () => this.unsupported()
})();
}
show() {
return _reactNative.Platform.select({
android: () => MakePayment.loadPaymentData(this.paymentMethods[GOOGLE_PAY_PMI]),
default: () => this.unsupported()
})();
}
unsupported() {
return new Promise((resolve, reject) => {
reject('Platform not supported');
});
}
}
module.exports = {
PaymentRequest,
GooglePayButton: _GooglePayButton.GooglePayButton,
GooglePayButtonConstants: _GooglePayButton.GooglePayButtonConstants
};
//# sourceMappingURL=index.js.map
;