The buyer makes a payment for the goods. In this step, we define the BuyerDepositPayment transaction and related event and update the LC status:
transaction BuyerDepositPayment {
--> LetterOfCredit lc
}
event BuyerDepositPaymentEvent {
--> LetterOfCredit lc
}
The letter status is set to BUYER_DEBIT_PAYMENT, and the step to 7:
/**
* buyer Deposit Payment
* @param {org.example.lc.BuyerDepositPayment} buyerDepositPayment - buyer Deposit Payment
* @transaction
*/
async function buyerDepositPayment(request) { // eslint-disable-line no-unused-vars
const factory = getFactory();
const namespace = 'org.example.lc';
let letter = request.lc;
if (letter.status === 'CLOSED') {
throw new Error ('This letter of credit has already been closed');
} else if (letter.step!== 6) {
throw new Error ('This letter of credit should be in step 6 - DELIVERY_DOCUMENT');
}
letter.status = 'BUYER_DEBIT_PAYMENT';
letter.step=7;
const assetRegistry = await getAssetRegistry(request.lc.getFullyQualifiedType());
await assetRegistry.update(letter);
// emit event
const buyerDepositPaymentEvent = factory.newEvent(namespace, 'BuyerDepositPaymentEvent');
buyerDepositPaymentEvent.lc = letter;
emit(buyerDepositPaymentEvent);
}