First of all, I am just asking that is it possible to create ARBsubscription using bank account. Almost all the example showing using credit card. But I want to do it using bank account. I am using "anet_php_sdk". Although there is also ARB with credit card in the sample code. But I changed a bit like -
<?php
require_once 'anet_php_sdk/AuthorizeNet.php';
define("AUTHORIZENET_API_LOGIN_ID", "YOURLOGIN");
define("AUTHORIZENET_TRANSACTION_KEY", "YOURKEY");
$subscription = new AuthorizeNet_Subscription;
$subscription->name = "PHP Monthly Magazine";
$subscription->intervalLength = "1";
$subscription->intervalUnit = "months";
$subscription->startDate = "2017-05-12";
$subscription->totalOccurrences = "12";
$subscription->trialOccurrences = "1";
$subscription->amount = "45.00";
$subscription->bankAccountAccountType = "CHECKING";
$subscription->bankAccountRoutingNumber= "121042882";
$subscription->bankAccountAccountNumber= "123456789123";
$subscription->bankAccountNameOnAccount= "Test Test1";
$subscription->bankAccountEcheckType = "WEB";
$subscription->bankAccountBankName = "Bank of Earth";
/*$subscription->creditCardCardNumber = "4007000000027";
$subscription->creditCardExpirationDate= "2018-10";
$subscription->creditCardCardCode = "123";*/
$subscription->billToFirstName = "test";
$subscription->billToLastName = "test1";
// Create the subscription.
$request = new AuthorizeNetARB;
$response = $request->createSubscription($subscription);
echo "<pre>";
print_r($response);
die();
$subscription_id = $response->getSubscriptionId();
?>
Yes, you can use a bank account with subscriptions. Page 22 of their guide lists all of the available fields to do so.
In your example you have both a credit card and bank payment account which is invalid. You need to remove the credit card lines of code.
Related
I’m attempting to test Accept Hosted payment page(redirect-method) with my sandbox. For this, I’m using the GetAnAcceptPaymentPage from the Java sample code application to generate a token string for a payment, specified the autoLoginId and transactionKey for my sandbox, and setting $1.00 as the amount. I’m then posting the returned token string to https://test.authorize.net/payment/payment with a “token” form element containing that string. This much appears to be working, and I do get a payment page showing the $1.00 amount. However, no matter what values I enter onto that payment page, pressing the “Pay” button just shows “The transaction has been declined.” in red text at the bottom of the form. I’ve confirmed that my sandbox is set to “Live” mode, and have looked at the following link to use what I believe should be valid values for testing: https://developer.authorize.net/hello_world/testing_guide/. I'm hoping someone can tell me why I can't get any result other than "The transaction has been declined".
public String getTokenValue() {
ApiOperationBase.setEnvironment(Environment.SANDBOX);
MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType();
merchantAuthenticationType.setName("xxxxx");
merchantAuthenticationType.setTransactionKey("xxxxxx");
ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
// Create the payment transaction request
TransactionRequestType txnRequest = new TransactionRequestType();
txnRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_TRANSACTION.value());
txnRequest.setAmount(new BigDecimal(1.00).setScale(2, RoundingMode.CEILING));
OrderExType order = new OrderExType();
order.setInvoiceNumber("2");
txnRequest.setOrder(order);
CustomerProfilePaymentType cpp = new CustomerProfilePaymentType();
cpp.setCustomerProfileId("xxxx");
cpp.setCreateProfile(true);
txnRequest.setProfile(cpp);
SettingType setting1 = new SettingType();
setting1.setSettingName("hostedPaymentButtonOptions");
setting1.setSettingValue("{\"text\": \"Proceed\"}");
SettingType setting2 = new SettingType();
setting2.setSettingName("hostedPaymentOrderOptions");
setting2.setSettingValue("{\"show\": false}");
SettingType setting3 = new SettingType();
setting3.setSettingName("hostedPaymentPaymentOptions");
setting3.setSettingValue("{\"cardCodeRequired\": true}");
SettingType setting4 = new SettingType();
setting4.setSettingName("hostedPaymentIFrameCommunicatorUrl");
setting4.setSettingValue("{\"url\": \"http://example.com/abc\"}");
ArrayOfSetting alist = new ArrayOfSetting();
alist.getSetting().add(setting1);
alist.getSetting().add(setting2);
alist.getSetting().add(setting3);
alist.getSetting().add(setting4);
GetHostedPaymentPageRequest apiRequest = new GetHostedPaymentPageRequest();
apiRequest.setTransactionRequest(txnRequest);
apiRequest.setHostedPaymentSettings(alist);
GetHostedPaymentPageController controller = new GetHostedPaymentPageController(apiRequest);
controller.execute();
GetHostedPaymentPageResponse response = new GetHostedPaymentPageResponse();
response = controller.getApiResponse();
if (response != null) {
if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
System.out.println(response.getToken());
} else {
System.out.println("Failed to get hosted payment page: " + response.getMessages().getResultCode());
}
}
return response.getToken();
}
>>> order.setInvoiceNumber("2");
Set the invoice number to a different value than 2, this value is used in Sandbox to trigger decline for testing purposes.
I am facing a very strange behavior in using the API to create the customer profiles. Although i have read the documentation thoroughly but did not succeed.
I am creating a customer profile at first when no profile is available along with a payment profile but next time when a user return and add the payment profile ( as the customer profile already exist) i am using only createCustomerPaymentProfile. The thing is, in first step i am not including $billto->setZip("44628"); and it goes well. But when i make only payment Profile it demands me to include the zip code too other wise it gives error
"There is one or more missing or invalid required fields."
I am using the exact same code which is in the php section of the documentation just a change in text/parameters.
create customer profile
create customer payment profile
For making the customer profile :
private function createCustomerProfile($data)
{
/* Create a merchantAuthenticationType object with authentication details
retrieved from the constants file */
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName("auth");
$merchantAuthentication->setTransactionKey("transkey");
// Set the transaction's refId
$refId = 'ref' . time();
$paymentProfile=$this->newPaymentProfile($data);
// Create a new CustomerProfileType and add the payment profile object
$customerProfile = new AnetAPI\CustomerProfileType();
$customerProfile->setDescription("Customer 2 Test PHP");
$customerProfile->setMerchantCustomerId($name. time());
$customerProfile->setEmail($email);
$customerProfile->setpaymentProfiles($paymentProfile);
// Assemble the complete transaction request
$request = new AnetAPI\CreateCustomerProfileRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setRefId($refId);
$request->setProfile($customerProfile);
// Create the controller and get the response
$controller = new AnetController\CreateCustomerProfileController($request);
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) {
$paymentProfiles = $response->getCustomerPaymentProfileIdList();
//Insert into database for the profile and payment profile update
} else {
echo "ERROR : Invalid response\n";
$errorMessages = $response->getMessages()->getMessage();
echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";
}
return $response;
For making the customer payment profile
private function createCustomerPaymentProfile($data){
/* Create a merchantAuthenticationType object with authentication details
retrieved from the constants file */
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName("name");
$merchantAuthentication->setTransactionKey("transkey");
// Set the transaction's refId
$refId = 'ref' . time();
$paymentProfile=$this->newPaymentProfile($data);
// Assemble the complete transaction request
$paymentprofilerequest = new AnetAPI\CreateCustomerPaymentProfileRequest();
$paymentprofilerequest->setMerchantAuthentication($merchantAuthentication);
// Add an existing profile id to the request
$paymentprofilerequest->setCustomerProfileId($data['profile_id']);
$paymentprofilerequest->setPaymentProfile($paymentProfile[0]);
$paymentprofilerequest->setValidationMode("liveMode");
// Create the controller and get the response
$controller = new AnetController\CreateCustomerPaymentProfileController($paymentprofilerequest);
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) {
echo "Create Customer Payment Profile SUCCESS: " . $response->getCustomerPaymentProfileId() . "\n";
//Insert into database for the profile and payment profile update
} else {
echo "Create Customer Payment Profile: ERROR Invalid response\n";
$errorMessages = $response->getMessages()->getMessage();
echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";
}
return $response;
}
for the re-usability purpose i have make a common make payment profile which return the payment profile array
private function newPaymentProfile($data){
// Set credit card information for payment profile
$creditCard = new AnetAPI\CreditCardType();
$creditCard->setCardNumber($data['account_number']);
$creditCard->setExpirationDate($data['date']);
$creditCard->setCardCode($data['securiy_no']);
$paymentCreditCard = new AnetAPI\PaymentType();
$paymentCreditCard->setCreditCard($creditCard);
// Create the Bill To info for new payment type
$billTo = new AnetAPI\CustomerAddressType();
$billTo->setFirstName($data['holder_name']);
$billTo->setAddress($data['billing_address']);
$billTo->setPhoneNumber($data['phone']);
$billTo->setfaxNumber($data['fax']);
// Create a new CustomerPaymentProfile object
$paymentProfile = new AnetAPI\CustomerPaymentProfileType();
$paymentProfile->setCustomerType('individual');
$paymentProfile->setBillTo($billTo);
$paymentProfile->setPayment($paymentCreditCard);
$paymentProfiles[]=$paymentProfile;
return $paymentProfiles;
}
I get the below error when running a custom workflow action that uses JSON.NET to serialize a dynamics object to JSON.
Is there a restriction on using reflection in CRM Dynamics customer workflow activities / plugins?
Is it because I am using dynamic variables?
System.TypeAccessException: Attempt by method
'DynamicClass.CallSite.Target(System.Runtime.CompilerServices.Closure,
System.Runtime.CompilerServices.CallSite, System.Object,
System.String)' to access type
'Newtonsoft.Json.Linq.JObject+JObjectDynamicProxy' failed. at
CallSite.Target(Closure , CallSite , Object , String ) at
WSWA.CRM.Logic.MyobIntegrationLogic.CreateInvoice(Boolean retry) at
WSWA.CRM.Workflows.MyobJob.MyobIntegrationTester.Execute(CodeActivityContext
context)
dynamic account = new JObject();
account.UID = GetAccount("Undeposited Funds Account");
dynamic job = new JObject();
job.UID = GetJob("JFC Interiors");
dynamic gstTaxCode = new JObject();
gstTaxCode.UID = GetTaxUidByCode("GST");
dynamic customer = new JObject();
customer.UID = GetCustomerUid("Bar001.test");
dynamic line1 = new JObject();
line1.Total = 22.55;
line1.Account = account;
line1.Job = job;
line1.TaxCode = gstTaxCode;
dynamic line2 = new JObject();
line1.Total = 23.55;
line1.Account = account;
line1.Job = job;
line1.TaxCode = gstTaxCode;
var lines = new JArray();
lines.Add(line1);
lines.Add(line2);
dynamic invoice = new JObject();
invoice.Date = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
invoice.Customer = customer;
invoice.CustomerPurchaseOrderNumber = "PO Number";
invoice.Number = "INV-1000";
invoice.Lines = lines;
var content = new StringContent(contact.ToString());
content.Headers.ContentType = MediaTypeHeaderValue.Parse("text/json");
var responseTask = httpClient.PostAsync(url, content);
Task.WaitAll(responseTask);
You can't use dynamic types in Dynamics (ironic isn't it?) CRM Sandboxed plugins. You can use reflection, as long as whatever you're reflecting is publicly available. i.e. You can use reflection to get a list of public properties, but you can't get a list of private fields.
You can always farm your work out to an Azure service and do whatever you'd like there.
There are known issues with dynamic types and using NuGet packages like Microsoft.AspNet.WebApi.Client.
Could you try with a WebClient?
More info here
I have an entity in CRM that has some Money fields on them. At the time of the creation of the entity there is no value for those fields, so the entity is created and saved. However if I then have values and go to update them (either through the UI or Web Services) I basically get an error stating "The currency cannot be null".
In the UI:
I then get a red circle with an X through it if I go to update the value.
In the code (web service call):
var crmService = new CrmServiceReference.IFAAContext(new Uri(crmWebServicesUrl));
crmService.Credentials = System.Net.CredentialCache.DefaultCredentials;
var crmAccount = crmService.AccountSet.Where(a => a.AccountId == accountId).FirstOrDefault();
crmAccount.myitems_MoneyValueItem.Value = 10.0m;
crmService.UpdateObject(crmAccount);
crmService.SaveChanges()
I then get the "The currency cannot be null" on the .SaveChanges() call.
In the code (second attempt):
var crmService = new CrmServiceReference.IFAAContext(new Uri(crmWebServicesUrl));
crmService.Credentials = System.Net.CredentialCache.DefaultCredentials;
var crmAccount = crmService.AccountSet.Where(a => a.AccountId == accountId).FirstOrDefault();
var crmCurrency = crmService.TransactionCurrencySet.Where(c => c.ISOCurrencyCode == "AUD").First();
crmService.SetLink(crmAccount, "TransactionCurrency_Account", crmCurrency);
//crmService.SaveChanges() /* tried with this uncommented as well to try and "set currency" before setting value */
crmAccount.myitems_MoneyValueItem.Value = 10.0m;
crmService.UpdateObject(crmAccount);
crmService.SaveChanges()
So this attempt fails in the same way, however if I run it a second time (without the currency and SetLink) so that the currency was saved before then it does work - hence the atempt to do a second .SaveChanges() but really need it to sort of work the first time through.
In the code (third attempt):
var crmService = new CrmServiceReference.IFAAContext(new Uri(crmWebServicesUrl));
crmService.Credentials = System.Net.CredentialCache.DefaultCredentials;
var crmAccount = crmService.AccountSet.Where(a => a.AccountId == accountId).FirstOrDefault();
crmAccount.athos_MoneyValueItem= new CrmServiceReference.Money() { Value = 10.0m };
crmService.UpdateObject(crmAccount);
crmService.SaveChanges()
This doesn't appear to work either
When you create a new record containing a Money field (or updating an existing one where no Money fields are filled before) , you need to specify the currency, the right field to set is TransactionCurrencyId (logical name transactioncurrencyid), it's a lookup (so inside the code is an EntityReference) to the currency entity.
assuming you have the Guid of your currency stored inside the currencyId variable:
var crmAccount = crmService.AccountSet.Where(a => a.AccountId == accountId).FirstOrDefault();
crmAccount.TransactionCurrencyId = new EntityReference(TransactionCurrency.LogicalName, currencyId);
crmAccount.myitems_MoneyValueItem = new Money(10.0m); //better to update the money field with this syntax
crmService.UpdateObject(crmAccount);
crmService.SaveChanges()
CRM 2013 expects a Money object for a currency field.
crmAccount.myitems_MoneyValueItem = new Money(10.0m);
You shouldn't have to explicitly declare a currency unless your CRM organization doesn't have a default currency set (and since you need to set this when creating an organization, it should always be set).
It looks like if I do a lookup on currency (shame as an extra data call) and then use that to set the TransactionCurrencyId it then "works" ... seems like I shouldn't have to do this as I do have a default set for the organisation though. But this does appear to be working in that it results in being able to update those fields.
var crmCurrency = crmService.TransactionCurrencySet.Where(c => c.ISOCurrencyCode == currencyCode).First();
var crmService = new CrmServiceReference.IFAAContext(new Uri(crmWebServicesUrl));
crmService.Credentials = System.Net.CredentialCache.DefaultCredentials;
var crmAccount = crmService.AccountSet.Where(a => a.AccountId == accountId).FirstOrDefault();
crmAccount.TransactionCurrencyId = new CrmServiceReference.EntityReference() { Id = crmCurrency.TransactionCurrencyId, LogicalName = "transactioncurrency", Name = crmCurrency.CurrencyName };
crmAccount.myitems_MoneyValueItem.Value = 10.0m;
crmService.UpdateObject(crmAccount);
crmService.SaveChanges();
i am doing the same thing as you but unable to set the money field value during service.create.
I have already put in
entity.Attributes["transactioncurrencyid"] = currencyGuid;
entity.Attributes["new_moneyfield"] = new Money(123.45M);
but in the end, the record is created with the transactioncurrency field populated, while the money field is blank.
Its a custom workflow on CRM online 2016 by the way..
I am trying to connect to the AX web services. What I will do it to fetch the right price given a product and a customer.
I realised the right webservice to use is PriceListServiceClient and I am able to log in to it using windows authentication, but I cannot retrieve any data from it.
Here is my code:
PriceListServiceClient priceListServiceClient = new PriceListServiceClient();
priceListServiceClient.ClientCredentials.Windows.ClientCredential.UserName = "yyy";
priceListServiceClient.ClientCredentials.Windows.ClientCredential.Password = "zzz!";
priceListServiceClient.ClientCredentials.Windows.ClientCredential.Domain = "xxx";
CriteriaElement[] criteriaElement = new CriteriaElement[1];
criteriaElement[0] = new CriteriaElement();
criteriaElement[0].DataSourceName = "SalesPrice";
criteriaElement[0].FieldName = "ItemId";
criteriaElement[0].Operator = Operator.NotEqual;
criteriaElement[0].Value1 = "5637153175";
QueryCriteria queryCriteria = new QueryCriteria();
queryCriteria.CriteriaElement = criteriaElement;
CallContext callContext = new CallContext();
var found = priceListServiceClient.find(callContext, queryCriteria);
Console.WriteLine(found.Currency);
priceListServiceClient.Close();
Any idea about why this is happening?
Try filling in the properties in the CallContext (company and language).
new CallContext { Company = "zzz", Language = "nl" };
I found the answer here: http://community.dynamics.com/ax/f/33/p/118741/246784.aspx
The Ax class for Price List document is AxPriceDiscTmpPrintout Class. This class wraps the TmpPriceDiscPrintout table, which is a TMP table. That's why you are not getting anything in return.