// tslint:disable:no-console import * as mongoose from 'mongoose'; import * as redis from 'redis'; import { chevre } from '../../../../lib/index'; import { orderProgramMembership } from '../../../../lib/chevre/service/transaction/orderProgramMembership'; const project = { id: String(process.env.PROJECT_ID) }; async function main() { await mongoose.connect(process.env.MONGOLAB_URI, { autoIndex: false }); const redisClient = redis.createClient({ host: process.env.REDIS_HOST, port: Number(process.env.REDIS_PORT), password: process.env.REDIS_KEY }); const personRepo = new chevre.repository.Person({ userPoolId: chevre.settings.userPoolIdNew }); const actionRepo = new chevre.repository.Action(mongoose.connection); const accountRepo = new chevre.repository.Account(mongoose.connection); const accountingReportRepo = new chevre.repository.AccountingReport(mongoose.connection); const assetTransactionRepo = new chevre.repository.AssetTransaction(mongoose.connection); const eventRepo = new chevre.repository.Event(mongoose.connection); const offerRepo = new chevre.repository.Offer(mongoose.connection); const offerCatalogRepo = new chevre.repository.OfferCatalog(mongoose.connection); const productRepo = new chevre.repository.Product(mongoose.connection); const projectRepo = new chevre.repository.Project(mongoose.connection); const ownershipInfoRepo = new chevre.repository.OwnershipInfo(mongoose.connection); const sellerRepo = new chevre.repository.Seller(mongoose.connection); const serviceOutputRepo = new chevre.repository.ServiceOutput(mongoose.connection); const taskRepo = new chevre.repository.Task(mongoose.connection); const transactionRepo = new chevre.repository.Transaction(mongoose.connection); const confirmationNumberRepo = new chevre.repository.ConfirmationNumber(redisClient); const orderNumberRepo = new chevre.repository.OrderNumber(redisClient); const registerServiceInProgressRepo = new chevre.repository.action.RegisterServiceInProgress(redisClient); const transactionNumberRepo = new chevre.repository.TransactionNumber(redisClient); const serviceOutputIdentifierRepo = new chevre.repository.ServiceOutputIdentifier(redisClient); const result = await orderProgramMembership( { agent: { typeOf: chevre.factory.personType.Person, id: 'b2bc2b6d-aea2-41fc-9f6e-e4ec89c11d2e', identifier: [ { name: 'tokenIssuer', value: String(process.env.ISS) }, { name: 'iss', value: String(process.env.ISS) } ] }, object: { seller: { id: '5d0abf30ac3fb200198ebb2c' }, typeOf: chevre.factory.offerType.Offer, itemOffered: { typeOf: chevre.factory.permit.PermitType.Permit, name: '[development]会員ポイントプログラム', issuedThrough: { id: '5afff104d51e59232c7b481b', typeOf: chevre.factory.product.ProductType.MembershipService } }, id: '7k9f3ht34', identifier: 'AnnualPlan' }, project: { typeOf: chevre.factory.organizationType.Project, id: project.id }, typeOf: chevre.factory.actionType.OrderAction }, 'CreditCard' )({ account: accountRepo, accountingReport: accountingReportRepo, action: actionRepo, assetTransaction: assetTransactionRepo, confirmationNumber: confirmationNumberRepo, event: eventRepo, offer: offerRepo, offerCatalog: offerCatalogRepo, orderNumber: orderNumberRepo, ownershipInfo: ownershipInfoRepo, person: personRepo, product: productRepo, project: projectRepo, registerActionInProgress: registerServiceInProgressRepo, seller: sellerRepo, serviceOutput: serviceOutputRepo, serviceOutputIdentifier: serviceOutputIdentifierRepo, task: taskRepo, transaction: transactionRepo, transactionNumber: transactionNumberRepo }); console.log(result); } main() .then(console.log) .catch(console.error);