Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@dowelllabs/dowellpayment
Advanced tools
Readme
Welcome to the Dowell Payment package!.A simple npm package for initiating and verifying payments using Stripe or PayPal.
Install the package using npm:
npm install @dowelllabs/dowellpayment
Import the package and use the Payment class to initiate and verify payments using either Stripe or PayPal.
import { useState } from 'react';
import { DowellPaypal } from '@dowelllabs/dowellpayment'; // Adjust the path to the actual location of Payment.js
const PayPal = () => {
const [paymentResult, setPaymentResult] = useState();
const [approvalUrl, setApprovalUrl] = useState();
const [paymentId, setPaymentId] = useState();
const apiKey = 'YOUR_API_KEY';
const paypal_client_id = 'YOUR_PAYPAL_CLIENT_ID';
const paypal_secret_key = 'YOUR_PAYPAL_SECRET_KEY';
const mode = 'YOUR_PAYPAL_MODE'; // live or sandbox
const handleInitializePayment = async () => {
try {
const userEnteredPrice = 500.5; // Example user input (replace with actual user input)
let formattedPrice = parseFloat(userEnteredPrice).toFixed(2);
const initializationResult = await new DowellPaypal().initializePayment({
apiKey: apiKey,
price: formattedPrice,
product: 'Product Name',
currency_code: 'usd',
callback_url: 'https://www.google.com',
paypal_client_id: paypal_client_id,
paypal_secret_key: paypal_secret_key,
mode: mode,
});
console.log(initializationResult);
const data = JSON.parse(initializationResult);
setApprovalUrl(data.approval_url);
setPaymentId(data.payment_id);
} catch (error) {
console.error('Error while initializing payment', error);
}
};
const handleVerifyPayment = async () => {
try {
const response = await new DowellPaypal().verifyPayment({
apiKey: apiKey,
paypal_client_id: paypal_client_id,
paypal_secret_key: paypal_secret_key,
mode: mode,
paymentId: paymentId,
});
if (response === 'false') {
console.error('Payment verification failed:', response);
} else {
setPaymentResult(response);
}
} catch (error) {
console.error('Error verifying payment:', error.message);
}
};
return (
<div>
<h1>PayPal Payment Component</h1>
<button onClick={handleInitializePayment}>Initiate Payment</button>
<a href={approvalUrl}>{approvalUrl}</a>
<hr />
{approvalUrl && (
<div>
<button onClick={handleVerifyPayment}>Verify Payment</button>
<p>Payment Result:</p>
<pre>{JSON.stringify(paymentResult, null, 2)}</pre>
</div>
)}
</div>
);
};
export default PayPal;
import { useState } from 'react';
import { DowellStripe } from '@dowelllabs/dowellpayment'; // Adjust the path to the actual location of Payment.js
const Stripe = () => {
const [paymentResult, setPaymentResult] = useState();
const [approvalUrl, setApprovalUrl] = useState();
const [paymentId, setPaymentId] = useState();
const apiKey = 'YOUR_API_KEY';
const stripe_key = 'YOUR_STRIPE_KEY';
const handleInitializePayment = async () => {
try {
const userEnteredPrice = 500.5; // Example user input (replace with actual user input)
let formattedPrice = parseInt(userEnteredPrice);
const initializationResult = await new DowellStripe().initializePayment({
apiKey: apiKey,
price: formattedPrice,
product: 'Product Name',
currency_code: 'usd',
callback_url: 'https://www.google.com',
stripe_key: stripe_key,
});
console.log(initializationResult);
const data = JSON.parse(initializationResult);
setApprovalUrl(data.approval_url);
setPaymentId(data.payment_id);
} catch (error) {
console.error('Error while initializing payment', error);
}
};
const handleVerifyPayment = async () => {
try {
const response = await new DowellStripe().verifyPayment({
apiKey: apiKey,
stripe_key: stripe_key,
paymentId: paymentId,
});
if (response === 'false') {
console.error('Payment verification failed:', response);
} else {
setPaymentResult(response);
}
} catch (error) {
console.error('Error verifying payment:', error.message);
}
};
return (
<div>
<h1>Stripe Payment Component</h1>
<button onClick={handleInitializePayment}>Initiate Payment</button>
<a href={approvalUrl}>{approvalUrl}</a>
<hr />
{approvalUrl && (
<div>
<button onClick={handleVerifyPayment}>Verify Payment</button>
<p>Payment Result:</p>
<pre>{JSON.stringify(paymentResult, null, 2)}</pre>
</div>
)}
</div>
);
};
export default Stripe;
initializePayment(apiKey,price, product, currency, callbackUrl, timezone, description, credit) Initiates a payment using the paypal payment method.
apiKey
: Your API key for accessing the process module service.price
: The price of the product(Paypal only supported price of 2 decimal point at most).product
: The name of the product.currency
: The currency code (e.g., 'usd').callbackUrl
: The URL to which the payment service will redirect after payment.paypal_client_id
: Your PAYPAL CLIENT ID for accessing paypal payment service.paypal_secret_key
: Your PAYPAL SECRET key for accessing paypal payment service.mode
: For testing or live mode. Set the mode to sandbox incase you wanted to test the API or set the mode to live incase you wanted to switch to live mode and make sure that your Paypal_Client_Id and Paypal_Secret_key is attached to your live app in your paypal account-verifyPayment(paymentId, apiKey)
Verifies a payment using the specified payment method for paypal.
apiKey
: Your API key for accessing the process module service.paypal_client_id
: Your PAYPAL CLIENT ID for accessing paypal payment service.paypal_secret_key
: Your PAYPAL SECRET key for accessing paypal payment service.paymentId
: The ID of the payment to verify.mode
: For testing or live mode. Set the mode to sandbox incase you wanted to test the API or set the mode to live incase you wanted to switch to live mode and make sure that your Paypal_Client_Id and Paypal_Secret_key is attached to your live app in your paypal accountinitializePayment(apiKey,price, product, currency, callbackUrl, timezone, description, credit) Initiates a payment using the stripe payment method.
apiKey
: Your API key for accessing the process module service.price
: The price of the product( Stripe only support whole number).product
: The name of the product.currency
: The currency code (e.g., 'usd').callbackUrl
: The URL to which the payment service will redirect after payment.stripe_key
: Your STRIPE key for accessing stripe payment service.-verifyPayment(paymentId, apiKey)
Verifies a payment using the specified payment method for stripe.
apiKey
: Your API key for accessing the process module service.stripe_key
: Your STRIPE key for accessing stripe payment service.paymentId
: The ID of the payment to verify.Stripe supports paying in local currency across more than 135 countries.
PayPal supports paying in local currency in 25 countries.
And also Paypal only supported price of 2 decimal point at most as part of the request body While Stripe only support whole number
This project is licensed under the Apache License 2.0.
FAQs
Welcome to the Dowell Payment package!
The npm package @dowelllabs/dowellpayment receives a total of 1 weekly downloads. As such, @dowelllabs/dowellpayment popularity was classified as not popular.
We found that @dowelllabs/dowellpayment demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.