// import MedipassTransactionSDK from '@medipass/partner-sdk';
// const MedipassTransactionSDK = require('@medipass/partner-sdk');
/**
* Retrieving payment methods for a patient by the patient ref id.
* 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: '61f1f842fb031da2373daaf6:drC6RAykRd0ecV-oCzOnx8dG6iHND8hSBuu-ygPlMCQ', // Can be found in your business settings in Connect
appId: 'web-application', // Your application identifier
appVersion: 'v1.0.0' // Your application version
});
// Patient Id must be supplied
const refId = '611a57d5506a87005f04e4ac';
let vale
try {
const { items } = await MedipassTransactionSDK.payments.getBusinessPatientPaymentMethodsByRefId({
query: {
refId
}
});
vale = items
} catch (e) {
console.log(e)
return
}
const items = vale
// 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";
...
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.