Skip to content

Instantly share code, notes, and snippets.

@fadliawan
Last active September 28, 2016 14:20
Show Gist options
  • Save fadliawan/da0b52de3e70a8af1ec253f5619981d5 to your computer and use it in GitHub Desktop.
Save fadliawan/da0b52de3e70a8af1ec253f5619981d5 to your computer and use it in GitHub Desktop.
Asura + Wyvern
// Asura (CustomerController.js)
static async postCustomerWithMagic(ctx, next) {
// .. something something
} else if (primary_id_type === 'customerId') {
let { isProvisioned } = await api.classify(primary_id, primary_id_type);
result = isProvisioned ? null :
await api.provision(customer.id, 'spAccountId', customer.sku, effectiveDate, primary_id);
} else {
// .. something something
ctx.json(result);
}
// Wyvern (SignupController.js)
*postOtp()
{
var activationResult = {};
try {
activationResult = yield postCustomer(this.session.country, this.request.body);
} catch (err) {
// FIXME: handle when activation failed
// however e.g. for telkomsel, the user is already provisioned
}
var createPath = activationResult.type === 'spAccountId' ? 'partnersCreateCustomer' : 'createCustomer';
// create user
var customerParam = {
ipAddress: process.env[this.session.country + '_CREDENTIALS_API_IP'],
apiuser: process.env.EVERGENT_API_USER,
apipassword: process.env.EVERGENT_API_PASSWORD,
contactUserName: this.request.body.email,
contactPassword: this.request.body.password,
phoneNumber: sanitizePhone(this.request.body.phone),
smsCode: this.request.body.otp, // <--- for primaryIdType === 'msisdn' || 'email'
spAccountId: activationResult.type === 'spAccountId' && activationResult.primaryId, // <--- for primaryIdType === 'customerId'
socialLoginID: this.request.body.socialid || null,
socialLoginType: this.request.body.socialid ? 'Facebook' : null,
channelPartnerID: this.request.body.cpid || process.env[this.session.country + '_CREDENTIALS_API_PARTNERID'],
locale: process.env.EVERGENT_API_LOCALE
},
response = yield request.post({ url: process.env.EVERGENT_API_DOMAIN + createPath, form: customerParam });
response = JSON.parse(response.body);
// .. something something
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment