Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Created by Vatsal Shukla on 16-Dec-2019
- *
- * Descriptioin:-
- * this class is created to fetch & insert Access_Token & refresh_token & client_id & client_secrate
- *
- */
- public class XeroSettings {
- //---- Properties---------
- private Xero_Setting__c settings;
- public String tenantId {
- get {
- return this.tenantId;
- }
- set {
- System.debug('MARK:==> XeroSettings --> tenantId --'+value);
- this.tenantId = value;
- }
- }
- public String accessToken {
- get {
- return this.accessToken;
- }
- set {
- System.debug('MARK:==> XeroSettings --> accessToken --'+value);
- this.accessToken = value;
- }
- }
- public String authCode {
- get {
- return this.authCode;
- }
- set {
- System.debug('MARK:==> XeroSettings --> authCode --'+value);
- this.authCode = value;
- }
- }
- public String clientId {
- get {
- return this.clientId;
- }
- set {
- System.debug('MARK:==> XeroSettings --> clientId --'+value);
- this.clientId = value;
- }
- }
- public String clientSecret {
- get {
- return this.clientSecret;
- }
- set {
- System.debug('MARK:==> XeroSettings --> clientSecret --'+value);
- this.clientSecret = value;
- }
- }
- public String refreshToken {
- get {
- return this.refreshToken;
- }
- set {
- System.debug('MARK:==> XeroSettings --> refreshToken --'+value);
- this.refreshToken = value;
- }
- }
- public Datetime expiryDate {
- get {
- return this.expiryDate;
- }
- set {
- System.debug('MARK:==> XeroSettings --> expiryDate --'+value);
- this.expiryDate = value;
- }
- }
- public Double expirySeconds {
- get {
- return this.expirySeconds;
- }
- set {
- System.debug('MARK:==> XeroSettings --> expirySeconds --'+value);
- this.expirySeconds = value == null ? 0:value;
- this.calculateExpiryDate(this.expirySeconds);
- }
- }
- //MARK:- Constructor
- public XeroSettings() {
- this.settings = [SELECT Id,Name,Xero_Tenant_Id__c,Access_Token__c,authCode__c,Client_Id__c,Client_secret__c,Refresh_Token__c,expired_in_seconds__c,Expiry_Date__c FROM Xero_Setting__c limit 1];
- this.accessToken = this.settings.Access_Token__c;
- this.tenantId = this.settings.Xero_Tenant_Id__c;
- this.authCode = this.settings.authCode__c;
- this.clientId = this.settings.Client_Id__c;
- this.clientSecret = this.settings.Client_secret__c;
- this.refreshToken = this.settings.Refresh_Token__c;
- this.expirySeconds = this.settings.expired_in_seconds__c;
- this.expiryDate = this.settings.Expiry_Date__c;
- }
- //MARK:-
- public void save() {
- this.settings.expired_in_seconds__c = this.expirySeconds;
- this.settings.Access_Token__c = this.accessToken;
- this.settings.Refresh_Token__c = this.refreshToken;
- this.settings.Expiry_Date__c = this.expiryDate;
- UPDATE this.settings;
- }
- public void addTenant(Tenant tnnt) {
- this.tenantId = tnnt.tenantId;
- System.debug('MARK:==> XeroSettings --> addTenant() --'+this.tenantId);
- }
- public void printSettings() {
- System.debug('MARK:==> XeroSettings = '+this.settings);
- }
- public Boolean checkTokenExpiredOrNot() {
- DateTime dt = this.expiryDate;
- if (dt > System.now()) {
- System.debug('MARK:==> XeroSetting - checkTokenExpiredOrNot() - not expired(false)');
- return false;
- } else {
- System.debug('MARK:==> XeroSetting - checkTokenExpiredOrNot() - expired(true)');
- return true;
- }
- }
- private void calculateExpiryDate(Double seconds) {
- if(seconds == 0) {
- return;
- }
- Double o = seconds;
- Integer expSeconds = Integer.valueOf(o);
- Datetime nextDatetime = System.now().addSeconds(expSeconds);
- this.expiryDate = nextDatetime;
- }
- }
Add Comment
Please, Sign In to add comment