• Miriam Lücke
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 4
    Replies
I have a http request method and I can't figure out how to cover my code. Can anybody help?
public static String basicAuthCallout(String PaymillToken, String Endpoint)
	{
		String PrivateKey = 'private';
		String PaymentId = 'wrong';
		HttpRequest req = new HttpRequest();
 		req.setEndpoint(Endpoint);
 		req.setMethod('POST');

 		//Set token for http request
 		req.SetBody('token='+PaymillToken);
 		system.debug(req.getBody());

		 // Specify the required password to access the endpoint (Private key)
		 // As well as the header and header information
			
		 Blob headerValue = Blob.valueOf(PrivateKey);
		 String authorizationHeader = 'BASIC ' +
		 EncodingUtil.base64Encode(headerValue);
		 req.setHeader('Authorization', authorizationHeader);
		
		 // Create a new http object to send the request object
		 // A response object is generated as a result of the request  

		system.debug(req);
		Http http = new Http();
		HTTPResponse res = http.send(req);
		String response = res.getBody();
		System.debug(response);
		integer startPoint = response.IndexOf('pay');
		if(startPoint > 0)
		{
			String temp = response.subString(startPoint);
			integer EndString = startPoint + temp.IndexOf('\",');
			PaymentId = response.subString(startPoint, EndString);
			system.debug(PaymentId);
		}
		
		return PaymentId;
	}

 
I have a visualforce to be rendered as pdf. It displays child records in a table. The language of the rendered pdf is based on a picklist from the parent record.
When the language is set to english, the table displays fine:
english table in pdf
When the language is set to german, the table displays distorted:
german table in pdf
The respective excerpt of my vf source code:
<!-- Start Discussion Points-->
        <table rules="rows" styleClass="table" cellpadding="4px">
            <tr>
                <td colspan="5"  style="font-weight:bold; text-align: left;font-size:11pt;"> {!$ObjectType.Discussion_Points__c.label}</td>
            </tr>
            <tr>
                <td class="col1"><strong>{!$ObjectType.Discussion_Points__c.fields.Name.label}</strong></td>
                <td class="col34"><strong>{!$ObjectType.Discussion_Points__c.fields.Category__c.label}</strong></td>
                <td class="col2" ><strong>{!$ObjectType.Discussion_Points__c.fields.Summary__c.label}</strong></td>
                <td class="col34"><strong>{!$ObjectType.Discussion_Points__c.fields.Responsible_selection__c.label}</strong></td>
                <td class="col34"><strong>{!$ObjectType.Discussion_Points__c.fields.Due_Date__c.label}</strong></td>
            </tr>
            <!-- Due_Date__c, Internal_use_only__c, No__c, Responsible_contact__c, Responsible_selection__c, Responsible_user__c, Subject__c, Summary__c, Trip_Report__c, Name   -->                                       
            <apex:repeat value="{!TripRepPoints}" var="item">
                <apex:outputpanel rendered="{!NOT(item.internal_use__c)}" >
                    <tr>
                        <td class="col1"><apex:outputfield value="{!item.Name}" /></td>
                        <td class="col34"><apex:outputfield value="{!item.Category__c}" /></td>
                        <td class="col2"><apex:outputfield value="{!item.Summary__c}" /></td>
                        <td class="col34"><apex:outputfield value="{!item.Responsible_company__c}" /></td>
                        <td class="col34"><apex:outputfield value="{!item.Due_Date__c}" /></td>
                    </tr>
                </apex:outputpanel>
            </apex:repeat>
        </table>        
<!-- End Discussion Points-->
And the related css:
.col1 {
 width: 15%;
 vertical-align: top;
 font-weight: bold;
 font-size: 10pt; 
 border-bottom: 1px solid #CCC;
 }
.col2 {
 border-left: 1px solid #CCC;
 border-right: 1px solid #CCC;
 border-bottom: 1px solid #CCC;
 width: 40%;
 font-size: 10pt; 
 vertical-align:top;
 
 }
.col34 {
 border-left: 1px solid #CCC;
 border-bottom: 1px solid #CCC;
 width: 15%;
 font-size: 10pt; 
 vertical-align:top;
 }

Maybe anyone has an idea why this happens?

Many thanks in advance!
 
I have some JS function which will create two vars. I write this var to a <apex:inputText> (will change this to inputHidden when it works). It appears in the field but after everything is done the var doesn't appear in the controller and so isn't saved. I did a lot of search but didn't come to a solution, so maybe you could help.
My Visualforce with JS (shortened):
<script type="text/javascript">
<!-- called from another function and works as expected-->
function paymillResponseHandler(error, result) 
{
    if (error) 
    {
      // Displays the error above the form
      alert(error.apierror);
    } 
    else 
    {
      // Output token
      var token = result.token;
      // Insert token into form in order to submit to server
     $("[id$=paymilltoken]").val(token);
     PassStringToController();
    }
} 
</script>
[....]
<apex:form id="paymentform">
...
    <apex:inputHidden value="{!PaymentId}" id="paymentid" />
    
    <apex:inputText value="{!PaymillToken}" id="paymilltoken" />
...
    <div style="float:left;"><br/>
        <p><apex:commandButton action="{!toRegistration}" value="{!$Label.Zur_ck}" styleClass="ab" /></p>
    </div>
    
    <div style="float:right;"><br/>
    <apex:inputHidden value="{!PaymillToken}" id="PaymillTokenField" />
        <p>
<apex:commandButton value="{!$Label.Weiter}" action="{!finishRegistration}" onclick="Paymillfunction();" /></p>
    </div>
</apex:form>
....
My Controller (shortened):
public without sharing class EventmanagementCtrler 
{
    public String PaymillToken{get;set;}
    public String PaymentId{get;set;}
	public Quellen_Kontakt_Zuordnung__c Teilnehmer {get;set;}

	// some more vars ...
	
	// Constructor
    public EventmanagementCtrler()
    {
    	// initialize
	    PaymentId = '';
	    PaymillToken = '';
	}
	...
	    public PageReference finishRegistration()
    {
		system.debug(this.PaymillToken);        	
    	Teilnehmer.Paymill_Token__c = this.PaymillToken; // Teilnehmer is created earlier in the whole process
    	Teilnehmer.Status__c = 'angemeldet';
        upsert Teilnehmer;
        return Page.Sonstiges;
    }
	...
}
Since I'm not that into JS it was hard work for me to get that far - maybe I just don't see a small thing which causes the issue.
I need to include an external library and pass the answer from the library to the controller. The example from the documentation works fine 'as is'. Here's the example (from https://developers.paymill.com/en/introduction/brief-instructions/):
<script type="text/javascript">
var PAYMILL_PUBLIC_KEY = '62477926916d4da496cf4f1a77c4175d';
</script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="https://bridge.paymill.com/"></script>
<script type="text/javascript">
$(document).ready(function () {

function PaymillResponseHandler(error, result) {
if (error) {
// Displays the error above the form
$(".payment-errors").text(error.apierror);
} else {
$(".payment-errors").text("");
var form = $("#payment-form");
// Token
var token = result.token;

// Insert token into form in order to submit to server
form.append("<input type='hidden' name='paymillToken' value='" + token + "'/>");
form.get(0).submit();
}
$(".submit-button").removeAttr("disabled");
}

$("#payment-form").submit(function (event) {
// Deactivate submit button to avoid further clicks
$('.submit-button').attr("disabled", "disabled");

if (!paymill.validateCardNumber($('.card-number').val())) {
$(".payment-errors").text("Invalid card number");
$(".submit-button").removeAttr("disabled");
return false;
}

if (!paymill.validateExpiry(
  $('.card-expiry-month').val(),
  $('.card-expiry-year').val())
) {
$(".payment-errors").text("Invalid expiration date");
$(".submit-button").removeAttr("disabled");
return false;
}

paymill.createToken({
number:         $('.card-number').val(),
exp_month:      $('.card-expiry-month').val(),
exp_year:       $('.card-expiry-year').val(),
cvc:            $('.card-cvc').val(),
cardholder:     $('.card-holdername').val(),
amount_int:     $('.card-amount-int').val(),   // Integer z.B. "4900" für 49,00 EUR
currency:       $('.card-currency').val()      // ISO 4217 z.B. "EUR"
}, PaymillResponseHandler);

return false;
});
});
</script>
<div class="payment-errors"></div>
<form id="payment-form" action="request.php" method="POST">
<input class="card-amount-int" type="hidden" value="4900" />
<input class="card-currency" type="hidden" value="EUR" />

<div class="form-row"><label>Card number</label>
<input class="card-number" type="text" value="4111111111111111" size="20" /></div>

<div class="form-row"><label>CVC (Prüfnummer)</label>
<input class="card-cvc" type="text" value="111" size="4" /></div>

<div class="form-row"><label>Name</label>
<input class="card-holdername" type="text" value="Joe Doe" size="20" /></div>

<div class="form-row"><label>Expiry Date (MM/YYYY)</label>
<input class="card-expiry-month" type="text" value="02" size="2" />
<span> / </span>
<input class="card-expiry-year" type="text" value="2015" size="4" /></div>

<div class="form-row"><label>Currency</label>
<input class="card-currency" type="text" value="EUR" size="20" /></div>

<button class="submit-button" type="submit">Submit</button>

</form>

Since I'm not that into JS, maybe someone could help me adopt this to Visualforce. I have more <apex:inputFields> on the VF-Page and a complete <apex:form> with own <apex:commandbutton> to submit the inputfields to the controller. I'd like to have only one form, if possible. If not, I'd like to send the "token" var from the JS to a controller variable.

Any help is appreciated!

I have a visualforce to be rendered as pdf. It displays child records in a table. The language of the rendered pdf is based on a picklist from the parent record.
When the language is set to english, the table displays fine:
english table in pdf
When the language is set to german, the table displays distorted:
german table in pdf
The respective excerpt of my vf source code:
<!-- Start Discussion Points-->
        <table rules="rows" styleClass="table" cellpadding="4px">
            <tr>
                <td colspan="5"  style="font-weight:bold; text-align: left;font-size:11pt;"> {!$ObjectType.Discussion_Points__c.label}</td>
            </tr>
            <tr>
                <td class="col1"><strong>{!$ObjectType.Discussion_Points__c.fields.Name.label}</strong></td>
                <td class="col34"><strong>{!$ObjectType.Discussion_Points__c.fields.Category__c.label}</strong></td>
                <td class="col2" ><strong>{!$ObjectType.Discussion_Points__c.fields.Summary__c.label}</strong></td>
                <td class="col34"><strong>{!$ObjectType.Discussion_Points__c.fields.Responsible_selection__c.label}</strong></td>
                <td class="col34"><strong>{!$ObjectType.Discussion_Points__c.fields.Due_Date__c.label}</strong></td>
            </tr>
            <!-- Due_Date__c, Internal_use_only__c, No__c, Responsible_contact__c, Responsible_selection__c, Responsible_user__c, Subject__c, Summary__c, Trip_Report__c, Name   -->                                       
            <apex:repeat value="{!TripRepPoints}" var="item">
                <apex:outputpanel rendered="{!NOT(item.internal_use__c)}" >
                    <tr>
                        <td class="col1"><apex:outputfield value="{!item.Name}" /></td>
                        <td class="col34"><apex:outputfield value="{!item.Category__c}" /></td>
                        <td class="col2"><apex:outputfield value="{!item.Summary__c}" /></td>
                        <td class="col34"><apex:outputfield value="{!item.Responsible_company__c}" /></td>
                        <td class="col34"><apex:outputfield value="{!item.Due_Date__c}" /></td>
                    </tr>
                </apex:outputpanel>
            </apex:repeat>
        </table>        
<!-- End Discussion Points-->
And the related css:
.col1 {
 width: 15%;
 vertical-align: top;
 font-weight: bold;
 font-size: 10pt; 
 border-bottom: 1px solid #CCC;
 }
.col2 {
 border-left: 1px solid #CCC;
 border-right: 1px solid #CCC;
 border-bottom: 1px solid #CCC;
 width: 40%;
 font-size: 10pt; 
 vertical-align:top;
 
 }
.col34 {
 border-left: 1px solid #CCC;
 border-bottom: 1px solid #CCC;
 width: 15%;
 font-size: 10pt; 
 vertical-align:top;
 }

Maybe anyone has an idea why this happens?

Many thanks in advance!
 
I have some JS function which will create two vars. I write this var to a <apex:inputText> (will change this to inputHidden when it works). It appears in the field but after everything is done the var doesn't appear in the controller and so isn't saved. I did a lot of search but didn't come to a solution, so maybe you could help.
My Visualforce with JS (shortened):
<script type="text/javascript">
<!-- called from another function and works as expected-->
function paymillResponseHandler(error, result) 
{
    if (error) 
    {
      // Displays the error above the form
      alert(error.apierror);
    } 
    else 
    {
      // Output token
      var token = result.token;
      // Insert token into form in order to submit to server
     $("[id$=paymilltoken]").val(token);
     PassStringToController();
    }
} 
</script>
[....]
<apex:form id="paymentform">
...
    <apex:inputHidden value="{!PaymentId}" id="paymentid" />
    
    <apex:inputText value="{!PaymillToken}" id="paymilltoken" />
...
    <div style="float:left;"><br/>
        <p><apex:commandButton action="{!toRegistration}" value="{!$Label.Zur_ck}" styleClass="ab" /></p>
    </div>
    
    <div style="float:right;"><br/>
    <apex:inputHidden value="{!PaymillToken}" id="PaymillTokenField" />
        <p>
<apex:commandButton value="{!$Label.Weiter}" action="{!finishRegistration}" onclick="Paymillfunction();" /></p>
    </div>
</apex:form>
....
My Controller (shortened):
public without sharing class EventmanagementCtrler 
{
    public String PaymillToken{get;set;}
    public String PaymentId{get;set;}
	public Quellen_Kontakt_Zuordnung__c Teilnehmer {get;set;}

	// some more vars ...
	
	// Constructor
    public EventmanagementCtrler()
    {
    	// initialize
	    PaymentId = '';
	    PaymillToken = '';
	}
	...
	    public PageReference finishRegistration()
    {
		system.debug(this.PaymillToken);        	
    	Teilnehmer.Paymill_Token__c = this.PaymillToken; // Teilnehmer is created earlier in the whole process
    	Teilnehmer.Status__c = 'angemeldet';
        upsert Teilnehmer;
        return Page.Sonstiges;
    }
	...
}
Since I'm not that into JS it was hard work for me to get that far - maybe I just don't see a small thing which causes the issue.
I need to include an external library and pass the answer from the library to the controller. The example from the documentation works fine 'as is'. Here's the example (from https://developers.paymill.com/en/introduction/brief-instructions/):
<script type="text/javascript">
var PAYMILL_PUBLIC_KEY = '62477926916d4da496cf4f1a77c4175d';
</script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="https://bridge.paymill.com/"></script>
<script type="text/javascript">
$(document).ready(function () {

function PaymillResponseHandler(error, result) {
if (error) {
// Displays the error above the form
$(".payment-errors").text(error.apierror);
} else {
$(".payment-errors").text("");
var form = $("#payment-form");
// Token
var token = result.token;

// Insert token into form in order to submit to server
form.append("<input type='hidden' name='paymillToken' value='" + token + "'/>");
form.get(0).submit();
}
$(".submit-button").removeAttr("disabled");
}

$("#payment-form").submit(function (event) {
// Deactivate submit button to avoid further clicks
$('.submit-button').attr("disabled", "disabled");

if (!paymill.validateCardNumber($('.card-number').val())) {
$(".payment-errors").text("Invalid card number");
$(".submit-button").removeAttr("disabled");
return false;
}

if (!paymill.validateExpiry(
  $('.card-expiry-month').val(),
  $('.card-expiry-year').val())
) {
$(".payment-errors").text("Invalid expiration date");
$(".submit-button").removeAttr("disabled");
return false;
}

paymill.createToken({
number:         $('.card-number').val(),
exp_month:      $('.card-expiry-month').val(),
exp_year:       $('.card-expiry-year').val(),
cvc:            $('.card-cvc').val(),
cardholder:     $('.card-holdername').val(),
amount_int:     $('.card-amount-int').val(),   // Integer z.B. "4900" für 49,00 EUR
currency:       $('.card-currency').val()      // ISO 4217 z.B. "EUR"
}, PaymillResponseHandler);

return false;
});
});
</script>
<div class="payment-errors"></div>
<form id="payment-form" action="request.php" method="POST">
<input class="card-amount-int" type="hidden" value="4900" />
<input class="card-currency" type="hidden" value="EUR" />

<div class="form-row"><label>Card number</label>
<input class="card-number" type="text" value="4111111111111111" size="20" /></div>

<div class="form-row"><label>CVC (Prüfnummer)</label>
<input class="card-cvc" type="text" value="111" size="4" /></div>

<div class="form-row"><label>Name</label>
<input class="card-holdername" type="text" value="Joe Doe" size="20" /></div>

<div class="form-row"><label>Expiry Date (MM/YYYY)</label>
<input class="card-expiry-month" type="text" value="02" size="2" />
<span> / </span>
<input class="card-expiry-year" type="text" value="2015" size="4" /></div>

<div class="form-row"><label>Currency</label>
<input class="card-currency" type="text" value="EUR" size="20" /></div>

<button class="submit-button" type="submit">Submit</button>

</form>

Since I'm not that into JS, maybe someone could help me adopt this to Visualforce. I have more <apex:inputFields> on the VF-Page and a complete <apex:form> with own <apex:commandbutton> to submit the inputfields to the controller. I'd like to have only one form, if possible. If not, I'd like to send the "token" var from the JS to a controller variable.

Any help is appreciated!