The code below is how to impletment stripe payment API, I was wondering if I just convert it to CFscript and call my normal variable will it work?
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
Stripe.apiKey = "sk_test_aHhoYVOnsayNSIleB1ETUCSq00vUOS9YVQ";
Map<String, Object> params = new HashMap<String, Object>();
ArrayList<String> paymentMethodTypes = new ArrayList<>();
paymentMethodTypes.add("card");
params.put("payment_method_types", paymentMethodTypes);
ArrayList<HashMap<String, Object>> lineItems = new ArrayList<>();
HashMap<String, Object> lineItem = new HashMap<String, Object>();
lineItem.put("name", "T-shirt");
lineItem.put("description", "Comfortable cotton t-shirt");
lineItem.put("amount", 500);
lineItem.put("currency", "usd");
lineItem.put("quantity", 1);
lineItems.add(lineItem);
params.put("line_items", lineItems);
params.put("success_url", "https://example.com/success?session_id={CHECKOUT_SESSION_ID}");
params.put("cancel_url", "https://example.com/cancel");
Session session = Session.create(params);
While not a direct conversion of the Java code you've provided above, it should be fairly straight-forward to do this with cfscript using http service functions. For example:
<cfscript>
secKey = "sk_test_xxxx";
/* create new http service */
httpService = new http();
httpService.setMethod("post");
httpService.setCharset("utf-8");
httpService.setUrl("https://api.stripe.com/v1/checkout/sessions");
/* add header */
httpService.addParam(type="header", name="Authorization", value="Bearer " & secKey);
/* add params */
httpService.addParam(type="formfield",name="success_url",value="https://example.com/success");
httpService.addParam(type="formfield",name="cancel_url",value="https://example.com/fail");
httpService.addParam(type="formfield",name="payment_method_types[]",value="card");
httpService.addParam(type="formfield",name="line_items[0][amount]",value="1000");
httpService.addParam(type="formfield",name="line_items[0][currency]",value="usd");
httpService.addParam(type="formfield",name="line_items[0][quantity]",value="1");
httpService.addParam(type="formfield",name="line_items[0][name]",value="widget");
/* make the http call */
result = httpService.send().getPrefix();
/* parse json and print id */
chkSession = DeserializeJSON(result.fileContent);
writeoutput(chkSession.id)
</cfscript>
Related
I am trying to learn DynamoDB from Amazon AWS,and have been able to retrieve data with success, however I am having a hard time converting it to usable form.
My goal is to convert the result to an ArrayList of my Data data type, which is a ValueObject class with attributes, getters and setters.
Thanks!
Map<String,String> expressionAttributesNames = new HashMap<>();
expressionAttributesNames.put("#network_asset_code","network_asset_code");
expressionAttributesNames.put("#temperature","temperature");
Map<String,AttributeValue> expressionAttributeValues = new HashMap<>();
expressionAttributeValues.put(":network_asset_codeValue", new AttributeValue().withS("17AB05"));
expressionAttributeValues.put(":temperature", new AttributeValue().withN("21"));
ScanRequest scanRequest = new ScanRequest()
.withTableName("things")
.withFilterExpression("#network_asset_code = :network_asset_codeValue and #temperature = :temperature")
.withExpressionAttributeNames(expressionAttributesNames)
.withExpressionAttributeValues(expressionAttributeValues);
ScanResult scanResult = client.scan(scanRequest);
List<Map<String,AttributeValue>> attributeValues = scanResult.getItems();
ArrayList<Data> dataArray = new ArrayList<>();
for (Map map: attributeValues) {
Data d = map.values();
dataArray.add(d);
}
You can use DynamoDBMapper to automagically convert DynamoDB items to Java objects (POJO) using annotations.
After a while I could get it right:
for (Map map: attributeValues) {
AttributeValue attr = (AttributeValue) map.get("network_asset_code");
Data d = new Data();
d.network_asset_code = attr.getS();
dataArray.add(d);
}
I am trying to integrate salesforce with exacttarget using the SOAP wsdl provided by Exacttarget.
I am able to generate apex classes , but on calling the create request , I get the error System.CalloutException: Web service callout failed.
Since I am new to apex , I am not sure if SOAP header request can be done only through http ? or can I do it through my class.
Please find below the code I am using.
exacttargetComWsdlPartnerapi.Soap soapReq = new exacttargetComWsdlPartnerapi.Soap();
exacttargetComWsdlPartnerapi.UsernameAuthentication authentication = new exacttargetComWsdlPartnerapi.UsernameAuthentication();
authentication.UserName = '******';
authentication.PassWord = '*****';
soapReq.inputHttpHeaders_x = new Map<String, String>();
soapReq.outputHttpHeaders_x = new Map<String, String>();
//String myData = 'smruti.bhargava#accenture.com.etdev:smruti#123';
//authentication = EncodingUtil.base64Encode(Blob.valueOf(myData));
soapReq.inputHttpHeaders_x.put('Authorization','Basic ' + authentication );SALESFORCE STUB
exacttargetComWsdlPartnerapi.CreateOptions optList = new exacttargetComWsdlPartnerapi.CreateOptions();
exacttargetComWsdlPartnerapi.ContainerID contnr = new exacttargetComWsdlPartnerapi.ContainerID();
exacttargetComWsdlPartnerapi.APIObject apiObj = new exacttargetComWsdlPartnerapi.APIObject();
exacttargetComWsdlPartnerapi.APIProperty apiProp = new exacttargetComWsdlPartnerapi.APIProperty();
List<exacttargetComWsdlPartnerapi.APIProperty> propList = new List<exacttargetComWsdlPartnerapi.APIProperty>();
apiProp.Name='EmailAddress';
apiprop.Value='ash123#gmail.com';
propList.add(apiProp);
apiObj.PartnerProperties=propList;
contnr.APIObject = apiObj;
optList.Container = contnr;
List<exacttargetComWsdlPartnerapi.APIObject> objList = new List<exacttargetComWsdlPartnerapi.APIObject>();
objList.add(apiObj);
exacttargetComWsdlPartnerapi.CreateResponse_element response = soapReq.Create(optList,objList);
System.debug('** Result ==>' + response);
I'm trying to call a webservice using username/pwd using the below client but I don't see the username/password being set in the headers
Client code
AttachmentWSImplService service = new AttachmentWSImplService();
AttachmentWS aws = service.getAttachmentWS();
BindingProvider bindingProvider = (BindingProvider) aws;
SOAPBinding sopadBinding = (SOAPBinding) bindingProvider.getBinding();
sopadBinding.setMTOMEnabled(true);
bindingProvider.getRequestContext().put(bindingProvider.USERNAME_PROPERTY,"p3xferdt");
bindingProvider.getRequestContext().put(bindingProvider.PASSWORD_PROPERTY,"92mnGg1Cb14D9hVhG1W5fZra4UI=");
Server code
SOAPMessageContext ctx = (SOAPMessageContext) wsCtx
.getMessageContext();
java.util.Map<java.lang.String, java.util.List<java.lang.String>> headers = (Map<String, List<String>>) ctx
.get(MessageContext.HTTP_REQUEST_HEADERS);
if (headers.keySet() != null && !headers.keySet().isEmpty()) {
Iterator<String> keys = headers.keySet().iterator();
while (keys.hasNext()) {
String key = (String) keys.next();
logger.info("HeaderKey->" + key);
logger.info("Header values->" + headers.get(key));
// getting Basic Authentication
String tmpusername = getUsernameFromAuthentication(key,
headers.get(key).toString());
Code looks ok to me, should work fine.
Anyways try accessing Request Header by
Headers headers = ex.getRequestHeaders();
List<String> ulist = headers.get(BindingProvider.USERNAME_PROPERTY);
List<String> plist = headers.get(BindingProvider.PASSWORD_PROPERTY);
PS: Remember USERNAME_PROPERTY is static string from BindingProvider interface, can be accessed in Static way. (Coding standards :))
while make a webservice call out I am getting below error:
Web service callout failed: Unexpected element. Parser was expecting element 'http://schemas.xmlsoap.org/soap/envelope/:Envelope' but found ':HTML'
Please see below code which I am trying for this:
public class TestUtility_Cls{
public list<Test_webService.KeyValuePair> IOG_pair = new list<Test_webService.KeyValuePair>();
public pageReference calltestServices(){
I_pair = new list<Test_webService.KeyValuePair>();
Test_webService.webPort bindobj = new Test_Iwebervice.RtPort();
bindobj.clientCertName_x = 'xxxxxxxxxxxxxx';
bindobj.timeout_x = 120000;
bindobj.inputHttpHeaders_x = new Map<String, String>();
bindobj.inputHttpHeaders_x.put('Authorization', 'xxxxxxxxx');
Test_webService.KeyValuePair I_KeyValue = new Test_webService.KeyValuePair();
I_KeyValue.key = 'SessionId';
I_KeyValue.value = 'Carrie09';
I_pair.add(I_KeyValue);
I_KeyValue = new Test_webService.KeyValuePair();
I_KeyValue.key = 'CR';
I_KeyValue.value = 'ExOffer';
I_pair.add(I_KeyValue);
Test_webService.ArrayOfKeyValuePair kevapair = new Test_webService.ArrayOfKeyValuePair();
kevapair.attribute = I_pair;
Test_webService.ProcessEventResponse_element IResp = new Test_webService.ProcessEventResponse_element();
IResp = bindingobj.ProcessEvent('QA', 'GetOffers', kevapair);
return null;
}
}
Here I am using WSDL generated class's method.
Can someone help on this. How to resolve it?
Thanks,
public pageReference calltestServices(){
I think above method refers a html page reference from which you are extracting your input data.You are forming your input request in html format while your webservice is expectng soap envelope. I think you need to wrap or convet or edit your request, formed in above method as soap envelope, then only your server accept it.
i want to create a event but i just no idea how to change the event picture. I knew this is very old question but still i can't find any solution yet and i'm giving up soon... please at least tell me is this bugs from Facebook or anything else?
Here is my code :
Facebook.FacebookClient fb = new Facebook.FacebookClient(accessToken);
Dictionary<string, object> ev = new Dictionary<string, object>();
ev.Add("name", model.name);
ev.Add("start_time", model.start_time);
ev.Add("end_time", model.end_time);
ev.Add("description", model.description);
ev.Add("location", model.location);
ev.Add("privacy_type", model.privacy_type);
ev.Add("is_date_only", model.is_date_only);
//ev.Add("picture", "#https://fbcdn-photos-g-a.akamaihd.net/hphotos-ak-ash3/c0.0.50.50/p50x50/601514_10151470263757778_629077232_s.jpg"); //NOT WORKING
//ev.Add("source", "#https://fbcdn-photos-g-a.akamaihd.net/hphotos-ak-ash3/c0.0.50.50/p50x50/601514_10151470263757778_629077232_s.jpg"); //NOT WORKING
//ev.Add("picture", HttpUtility.UrlEncode("#https://fbcdn-photos-g-a.akamaihd.net/hphotos-ak-ash3/c0.0.50.50/p50x50/601514_10151470263757778_629077232_s.jpg")); //NOT WORKING
//ev.Add("source", HttpUtility.UrlEncode("https://fbcdn-photos-g-a.akamaihd.net/hphotos-ak-ash3/c0.0.50.50/p50x50/601514_10151470263757778_629077232_s.jpg")); //NOT WORKING
//ev.Add("picture", model.picture); //NOT WORKING
object EventId = fb.Post("/me/events", ev);
Dictionary<string, string> p = (new JavaScriptSerializer()).Deserialize<Dictionary<string, string>>(EventId.ToString());
Dictionary<string, object> pic = new Dictionary<string, object>();
//pic.Add("source", model.picture); //NOT WORKING
//pic.Add("picture", HttpUtility.UrlEncode("https://fbcdn-photos-g-a.akamaihd.net/hphotos-ak-ash3/c0.0.50.50/p50x50/601514_10151470263757778_629077232_s.jpg")); //NOT WORKING
//pic.Add("source",HttpUtility.UrlEncode("https://fbcdn-photos-g-a.akamaihd.net/hphotos-ak-ash3/c0.0.50.50/p50x50/601514_10151470263757778_629077232_s.jpg")); //NOT WORKING
object objPicture = fb.Post("/" + p["id"] + "/picture", pic);
The access token, picture URI and create new event is working fine but not picture.
First you need to realise there are 2 types of pictures for a Facebook event. The old style picture and the new Cover Photo.
If you want to do the old style picture you don't give it a url, you need to pass it the data in one of the arguments to the picture argument.
var arguments = new Dictionary<string, object>();
var mediaSource = new FacebookMediaObject
{
FileName = "image.jpg",
ContentType = "image/jpeg"
};
mediaSource.SetValue(webClient.DownloadData(url));
arguments.Add("picture", mediaSource);
Object value = client.Post(String.Format("/{0}/events/", "facebook_pageId_here"), arguments);
if you want to update that picture it is best to do
var arguments = new Dictionary<string, object>();
var mediaSource = new FacebookMediaObject
{
FileName = "image.jpg",
ContentType = "image/jpeg"
};
mediaSource.SetValue(webClient.DownloadData(url));
arguments.Add("source", mediaSource);
Object value = client.Post(String.Format("/{0}/picture/", "event_id_here"), arguments);
Now if you want to do the cover photo, the only thing I have managed to get working so far is by passing in a url to the cover_url parameter.
arguments.Add("cover_url", "http://domain.com/image.jpg");