// import MedipassTransactionSDK from '@medipass/partner-sdk';
// const MedipassTransactionSDK = require('@medipass/partner-sdk');
/**
* Retrieving payment methods for a patient.
* A patient can only have 1 payment method. Therefore, the
* items array only supports a single item currently.
*
* Example response:
* {
* "items": [
* {
* "cardType": "Visa",
* "expiryMonth": "02",
* "expiryYear": "2025",
* "isDebit": false,
*. "lastFour": "4242",
* }
* ...
* ]
* }
*/
async function main() {
await MedipassTransactionSDK.setConfig({
env: 'stg', // Enter the environment you want to target (stg/prod)
apiKey: 'your-api-key', // Can be found in your business settings in Connect
appId: 'web-application', // Your application identifier
appVersion: 'v1.0.0' // The transaction SDK version to target
});
// Patient Id must be supplied
const patientId = '6243f1695ef93900672ef327';
const { items } = await MedipassTransactionSDK.payments.getBusinessPatientPaymentMethods({
query: {
patientId
}
});
// Use the first item since a patient can only have a single paytment method currently.
const mainPaymentMethod = items[0];
if (!mainPaymentMethod) {
console.log("No payment method");
return;
}
document.getElementById('card-number').textContent = "**** " + mainPaymentMethod.lastFour;
document.getElementById('card-expiry').textContent = `${mainPaymentMethod.expiryMonth}/${mainPaymentMethod.expiryYear}`;
document.getElementById('card-json').textContent = JSON.stringify(mainPaymentMethod);
const cardNumbersElements = document.querySelectorAll('#card-number, #card-expiry');
const newTextColor = mainPaymentMethod.isExpired ? "red" : "black";
cardNumbersElements.forEach((cardNumberElement) => {
cardNumberElement.style.color = newTextColor;
});
}
main();
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.