How to use set_result with transacion in endpoint (Netzke gem) - netzke

I have create an endpoint for create new Client.
At first I have create Client and use transaction (see code below).
It's work normally.
# Before add set_result
js_method :on_new_contact, <<-JS
function() {
var form = this.items.first().getForm();
if (form.isValid()) {
this.newContact(form.getFieldValues());
this.closeRes = 'create_user';
this.close();
}
}
JS
endpoint :new_contact do |params|
data_hash = params.to_hash
Client.transaction do
new_client = Client.new
data_hash.each do |field, value|
new_client.__send__("#{field}=", value)
end
if new_client.save!
flash :notice => "Client #{new_client.full_name} has been created"
else
flash :error => new_user.errors.full_messages.to_sentence
end # if
end # transaction
{:netzkeFeedback => #flash}
end # endpoint
And after I have add set result for return new Client id from endpoint.
It's save new Client 3 times to my database.
# After add set_result
js_method :on_new_contact, <<-JS
   function() {
     var form = this.items.first().getForm();
     if (form.isValid()) {
       this.newContact(form.getFieldValues(), function(value){
           alert(form);
           alert(value);
       }, this);
       this.closeRes = 'create_user';
       this.close();
     }
   }
 JS
 endpoint :new_contact do |params|
   data_hash = params.to_hash
   Client.transaction do
     new_client = Client.new
     data_hash.each do |field, value|
       new_client.__send__("#{field}=", value)
     end
     if new_client.save!
       flash :notice => "Client #{new_client.full_name} has been created"
     else
       flash :error => new_user.errors.full_messages.to_sentence
     end # if
   end # transaction
   {:netzkeFeedback => #flash, :set_result => new_client.id}
 end # endpoint
I already try to find what the problem.
And I found it happen when I use set_result with transaction.
If I remove transaction OR set_result code, it will work normally.
Then how can I make it work?

Related

Why "not defined" error returned when rendering an EJS template from ExpressJS app.locals variable?

ExpressjS Application End-Point (request)
app.get('/', (req, res, next) => {
db.collection('sys_params').find().toArray((err, sysParams) => {
if (err) throw err;
app.locals.landPageRolloverStatus = sysParams[0].landPageRolloverStatus;
app.locals.ludenourOnlineStatus = sysParams[0].ludenourOnlineStatus;
app.locals.ludenourContactUsEnabled = sysParams[0].ludenourContactUsEnabled;
app.locals.ludenourJobsEnabled = sysParams[0].ludenourJobsEnabled;
console.log(sysParams)
app.locals.sysParams = sysParams;
});
res.render('index2');
next()
});
The error is related to the app.locals.sysParams.
ReferenceError: /Users/falswaimil/Documents/Project3X/Master/AIRECP/AirECPRetails/online-store/views/index2.ejs:39
   37|
   38| <a class="navbar-brand float-xs-right float-sm-left" href="http://localhost:3002/?clang=en"><img src="img/lu3.svg" class="img-fluid"/></a>
>> 39|         <% if (sysParams[0].ludenourOnlineStatus == "UC" ) { %>
   40|
   41|             <% if (clang == "en") {  %>
   42|                 <p style="color:red; font-family:Arial Rounded MT Bold; font-size:130%; text-align:center; width: 100%;"><%= __('SiteUnderConstruction') %></p>  
sysParams is not defined
However; when I refresh the page, the page is rendered without errors.
Because I am passing an expressJS application-level variable, it should be available on the EJS template across requests.
The issue with properly handling async operations. After using async/await in my middleware, the error resolved.
const readBootstrap = async(req, res, next) => {
await db.collection('sys_params').find().toArray()
.then(sysParams => {
app.locals.landPageRolloverStatus = sysParams[0].landPageRolloverStatus;
app.locals.ludenourOnlineStatus = sysParams[0].ludenourOnlineStatus;
app.locals.ludenourContactUsEnabled = sysParams[0].ludenourContactUsEnabled;
app.locals.ludenourJobsEnabled = sysParams[0].ludenourJobsEnabled;

Google pay not visible on android chrome device if the allowedCardAuthMethod is CRYPTOGRAM 3DS

In Android Chrome, When trying to initialize Google pay with allowedCardAuthMethod as Cryptogram 3ds, not able to view the google pay button
I am trying from India.
sample code: https://jsfiddle.net/dummy4150/8e2cbs6d/
const baseRequest = {
  apiVersion: 2,
  apiVersionMinor: 0
};
const allowedCardNetworks = ["AMEX", "DISCOVER", "INTERAC", "JCB", "MASTERCARD", "VISA"];
const allowedCardAuthMethods = ["CRYPTOGRAM_3DS"];
const tokenizationSpecification = {
  type: 'PAYMENT_GATEWAY',
  parameters: {
    'gateway': 'example',
    'gatewayMerchantId': 'exampleGatewayMerchantId'
  }
};
const baseCardPaymentMethod = {
  type: 'CARD',
  parameters: {
    allowedAuthMethods: allowedCardAuthMethods,
    allowedCardNetworks: allowedCardNetworks
  }
};
const cardPaymentMethod = Object.assign(
  {},
  baseCardPaymentMethod,
  {
    tokenizationSpecification: tokenizationSpecification
  }
);
Since you've specified allowedCardAuthMethods as CRYPTOGRAM_3DS and that you are trying from India, Here are a couple of things you could try:
Add a tokenized card to Google Pay (one that can be used for Tap and Pay)
Generally, Google Pay isn't currently supported in India, join the googlepay-test-mode-stub-data to use predefined test data that can be used in India (more info)
Create a new Google Account for testing based outside of India (suggest using USA) and add a tokenized card to that account

Powershell: Selecting individual values from JSON response

I'm testing code to send payment details as JSON which is working however I'm struggling to extract information from the JSON response.
I need to extract the content part of the JSON response as individual values so I can assign them to variables then insert them into a SQL table.
The response is assigned to $Result . I've tried $Result.content though obviously this gives you the whole content section. Is there a way to obtain individual values from content without going down the substring route?
Here is an example of a response:
{"transaction":{"id":"83123b05-2435-40c9-851d-a5636f092637","processed_at":"2019-04-05T13:02:19.689188Z","transaction_type":"Debit","currency_code":"GBP","amount":25000,"recipient_id":"8a659242-8e70-47e1-85ca-2fe18cb262a0","status":"Waiting for funds","status_info":"Insufficient Funds To Process","reconciliation":null,"reference":"D000000516","account_id":"07b286ad-dabc-42a7-ab1b-5302fd382e6c","tag":null,"end_balance":null,"idempotent_key":"1f25e9f8-64cf-4e91-b4d3-8753437b6dbb","created_at":"2019-04-05T13:02:19Z","updated_at":"2019-04-05T13:02:19Z"}}
Here is my Powershell Code:
cls
$Uri = "uriaddress"
$Content = Get-content C:\Test\BACS-DC190326093019.TXT | select-object -skip 4 
foreach($line in $Content){
  if($line.Substring(0,1) -match "[0-9]")
  {
  $sorcode = $line.Substring(0,6)
  $sorcode 
  $accountNumber =   $line.Substring(6,8)
  $accountNumber
  $CustomerName = $line.Substring(82,18)
  $CustomerName
  $FundingAmount = $line.Substring(41,5)
  $FundingAmount = $FundingAmount 
  $FundingAmount
  $Identifier = $line.Substring(64,10)
  $idempotent_key = New-Guid
  $body = #{
    "account_id"     = "000000"
    "currency_code"  = "GBP"
    "amount"         = $FundingAmount
    "recipient_name" = $CustomerName
    "account_no"     = $accountNumber
    "sort_code"      = $sorcode
    "idempotent_key" = $idempotent_key
    "reference"      = $Identifier
    "legal_type"     = "PRIVATE"
    }
    $headers = #{}
    $headers.Add("Authorization","00000000")
    $Result = ''
    $Result = Invoke-WebRequest -Uri $Uri -ContentType 'multipart/form-data' -Method Post -Headers $headers -Body $body 
 $Result.Content
    IF ($Result.StatusDescription -eq 'OK') { 
    write-host "Payment Sent Succesfully" -ForegroundColor Green
    } ELSE {
      write-host "Payment Failed Succesfully" -ForegroundColor Red
    }
    write-host ""
  }
}
PowerShell has built in support for processing JSON, so let's run your input through ConvertFrom-Json and see what we get.
$Result = '{"transaction":{"id":"83123b05-2435-40c9-851d-a5636f092637","processed_at":"2019-04-05T13:02:19.689188Z","transaction_type":"Debit","currency_code":"GBP","amount":25000,"recipient_id":"8a659242-8e70-47e1-85ca-2fe18cb262a0","status":"Waiting for funds","status_info":"Insufficient Funds To Process","reconciliation":null,"reference":"D000000516","account_id":"07b286ad-dabc-42a7-ab1b-5302fd382e6c","tag":null,"end_balance":null,"idempotent_key":"1f25e9f8-64cf-4e91-b4d3-8753437b6dbb","created_at":"2019-04-05T13:02:19Z","updated_at":"2019-04-05T13:02:19Z"}}'
$Result = $Result | Convertfrom-json
In your usage, you'd just run the last part to convert $Result into a PowerShell Object.
$Result has one property called .transaction where all of the info lives. We can get this out with the following syntax.
$result.transaction
id : 83123b05-2435-40c9-851d-a5636f092637
processed_at : 2019-04-05T13:02:19.689188Z
transaction_type : Debit
currency_code : GBP
amount : 25000
recipient_id : 8a659242-8e70-47e1-85ca-2fe18cb262a0
status : Waiting for funds
status_info : Insufficient Funds To Process
reconciliation :
reference : D000000516
account_id : 07b286ad-dabc-42a7-ab1b-5302fd382e6c
tag :
end_balance :
idempotent_key : 1f25e9f8-64cf-4e91-b4d3-8753437b6dbb
created_at : 2019-04-05T13:02:19Z
updated_at : 2019-04-05T13:02:19Z
So, now if we want to pull out specific values from there, we run the following.
C:\Users\Stephen> $result.transaction.amount
25000
C:\Users\Stephen> $result.transaction.status
Waiting for funds
C:\Users\Stephen> "Transaction in the amount of $($result.transaction.amount) -- status: $($result.transaction.status)"
Transaction in the amount of 25000 -- status: Waiting for funds
This should get you on your way.
Final tidbit, if you swap out Invoke-WebRequest for Invoke-RestMethod, the conversion from JSON is done for you automatically!

what is Jenkins file and how you will write

What is Jenkins file and How we will write?
How to create Jenkins job dynamically using DSL(I'm not aware of DSL)
From 30 page of Jenkins User Handbook: `Jenkinsfile is a text file that contains the definition of a Jenkins Pipeline and is checked into source control. In his chapter you can find examples of pipelines.
// Declarative //
pipeline {
agent any
  stages {
  stage('Build') {
  steps {
  echo 'Building..'
  }
  }
  stage('Test') {
  steps {
  echo 'Testing..'
  }
  }
  stage('Deploy') {
  steps {
  echo 'Deploying....'
  }
  }
}
// Script //
node {
  stage('Build') {
  echo 'Building....'
  }
  stage('Test') {
  echo 'Building....'
  }
  stage('Deploy') {
  echo 'Deploying....'
  }
}

Database Designing For Shared Data

I have an interesting question. I'm currently creating an app which involves a lot of shared data. What I mean by this is that within the app, users create groups in which they store important data also visible to other people in their groups. I want to store this shared data effectively, but I'm not sure which kind of database to use. One with a JSON tree format or one with query based search?
If there's an advantage to either I would appreciate an example. I'm already familiar of Firebase.
I think it all really depends on what will be the features of your app and what kind of data you would need to access, but considering a simple app with users, groups, conversations and messages, I would personally denormalize my data and use a database structure like this :
root/
|___ users/
|      |___ userID1
|              |___ name : user_name
|              |___ email : user_email
|              |___ picUrl : user_picture_url
|              |___ conversations
|                       |___ userConversationID1 : true                   
| |___ userConversationID2 : true
|                       ...
|              |___ groups
|                       |___ groupID1 : true                   
| |___ groupID2 : true
|                       ...
|              |___ notificationTokens
|                       |___ token1 : true                      
| |___ token2 : true
|                       ...
|
|___ groups/
|      |___ groupID1
|              |___ name : group_name
|              |___ thumbnailUrl : group_thumbnail_url
|              |___ conversations
|                       |___ groupConversationID1 : true                   
| |___ groupConversationID2 : true
|                       ...
|              |___ members
|                       |___ groupMemberID1 : true                   
| |___ groupMemberID2 : true
|                       ...
|
|___ conversations/
|      |___ conversationID1
|              |___ messageID1 : true
|              |___ messageID2 : true
|             |___ messageID3 : true
|             |___ messageID4 : true
|            ...
|      ...
|
|___ messages/
|      |___ messageID1
|              |___ text : message_text
|              |___ sender : message_sender
|              |___ receiver : message_receiver
|              |___ timestamp : message_timestamp
|      ...
|
|___ notifications/
|      ...
| ...
|
While this structure is indeed duplicating some data, I believe it makes it easier for you to look for the user-specific or group-specific data.
For instance if you would like to get a list of all the members of the group a simple
Database.database().reference().child("group").child(groupId).child("members").observeSingleEvent(of: .value, with: { (snapshot) in
// ...
})
would be enough, as opposed to a nested structure where it could end up being difficult getting the data you're looking for.
If you want just let me know what kind of features do you plan to have in your app and I could be more specific. I'd be glad to help you anyway :)
UPDATE:
With regards to which database you should choose (relational database vs Firebase) I would say that it's directly related to the features of your app. For example if you need to sort and filter a lot of data (filter users by age, country and gender) it might be better for you to go for a SQL Database as you would be able to filter easily only the users you're looking for. While not impossible, it would be more time (and data) consuming to do it using Firebase.
Now if you build a real-time chat for example, and don't need a too complex database structure for your app then obviously Firebase would be the one you're looking for because I think it makes it really fast and easy to use.