I have an existing implementation of this class processing subscriptions by credit card but I now need to add the facility to accept payment by eCheck but I am unsure of how to change this portion of the code:
'payment' => array(
'creditCard' => array(
'cardNumber' => '4111111111111111',
'expirationDate' => '2016-08'
)
),
I have come up with the following from referencing the AIM guide pdf and AIM guide XML pdf
'payment' => array(
'bankAccount' => array( // x_method equivalent ?
'routingNumber' => '', // x_bank_aba_code equivalent ?
'accountNumber' => '', // x_bank_acct_num equivalent ?
'nameOnAccount' => '', // x_bank_acct_name equivalent ?
'bankName' => '', // x_bank_name equivalent ?
'echeckType' => 'WEB' // x_echeck_type equivalent
/*
x_bank_acct_type has no equivalent ?
*/
)
),
but there appears to be some discrepancies between the required fields?
Any pointers before I start on this would be greatly appreciated.
Looking at Authorize.Net's documentation this should work:
'payment' => array(
'bankAccount' => array(
'accountType' => '', // 'checking'
'routingNumber' => '',
'accountNumber' => '',
'nameOnAccount' => ''
)
),
Following on from John's answer this is the complete code I used to solve this for anyone finding this through a google search:
$xml->ARBCreateSubscriptionRequest(array(
'subscription' => array(
'name' => 'SubscriptionName',
'paymentSchedule' => array(
'interval' => array(
'length' => '1',
'unit' => 'months'
),
'startDate' => date('Y-m-d', time()), // Format: YYYY-MM-DD
'totalOccurrences' => '9999' // To submit a subscription with no end date (an ongoing subscription), this field must be submitted with a value of 9999
),
'amount' => $eCart1->GrandTotal(), // total monthly subscription
'payment' => array(
'bankAccount' => array(
'accountType' => ((isset($_POST["accountType"]))?$_POST["accountType"]:""), // options available are checking or businessChecking in this instance
'routingNumber' => ((isset($_POST["routingNumber"]))?$_POST["routingNumber"]:""),
'accountNumber' => ((isset($_POST["accountNumber"]))?$_POST["accountNumber"]:""),
'nameOnAccount' => ((isset($_POST["nameOnAccount"]))?$_POST["nameOnAccount"]:""),
'echeckType' => ((isset($_POST["echeckType"]))?$_POST["echeckType"]:"") // if businessChecking is chosen then 'CCD' else 'WEB'
)
),
'customer' => array(
'id' => "'".$_SESSION['clientID']."'",
'email' => "'".((isset($_POST["email"]))?$_POST["email"]:"")."'"
),
'billTo' => array(
'firstName' => "'".((isset($_POST["firstname"]))?$_POST["firstname"]:"")."'",
'lastName' => "'".((isset($_POST["lastname"]))?$_POST["lastname"]:"")."'",
'company' => "'".((isset($_POST["company"]))?$_POST["company"]:"")."'",
'address' => "'".((isset($_POST["street1"]))?$_POST["street1"]:"")."'",
'city' => "'".((isset($_POST["city"]))?$_POST["city"]:"")."'",
'state' => "'".((isset($_POST["state_province"]))?$_POST["state_province"]:"")."'",
'zip' => "'".((isset($_POST["postcode"]))?$_POST["postcode"]:"")."'"
)
)
));
Related
Hello I am trying to apply the DRY concept to my program which now has over 3000 lines of codes just because i have been repeating myself a lot.
I have this array:
// prepare the sales payload
$sales_payload = array(
'organization_id' => $getOrg['data'][0]['id'],
'contact_id' => $contact_id,
'status' => 'Open',
'responsible_employee_id' => 'employee:50c76c15262b12d36d44e34a3f0f8c3d',
'source' => array(
'id' => $source['data'][0]['id'],
'name' => $source['data'][0]['name'],
),
'subject' => " ".str_replace($strToRemove, "", $_POST['billing_myfield12'])." - "."Online marketing Duitsland",
'start_date' => date("Y-m-d"), // set start date on today
'expected_closing_date' => date("Y-m-d",strtotime(date("Y-m-d")."+ 14 days")), // set expected closing date 2 weeks from now
'chance_to_score' => '10%',
'expected_revenue' => 0, //set the expected revenue
'note' => $_POST['order_comments'],
'progress' => array(
'id'=>'salesprogress:200a53bf6d2bbbfe' //fill a valid salesprogress id to set proper sales progress
),
"custom_fields" => [["voorstel_diensten"=>implode("-",$online_marketing_check)]],
);
Is there a way I can dynamically change certain fields only instead of copying the whole thing and manually changing it.
You can declare a function that clones the array and changes it
function arrayClone($args){
$sales_payload = array(
'organization_id' => $getOrg['data'][0]['id'],
'contact_id' => $contact_id,
'status' => 'Open',
'responsible_employee_id' => 'employee:50c76c15262b12d36d44e34a3f0f8c3d',
'source' => array(
'id' => $source['data'][0]['id'],
'name' => $source['data'][0]['name'],
),
'subject' => " ".str_replace($strToRemove, "", $_POST['billing_myfield12'])." - "."Online marketing Duitsland",
'start_date' => date("Y-m-d"), // set start date on today
'expected_closing_date' => date("Y-m-d",strtotime(date("Y-m-d")."+ 14 days")), // set expected closing date 2 weeks from now
'chance_to_score' => '10%',
'expected_revenue' => 0, //set the expected revenue
'note' => $_POST['order_comments'],
'progress' => array(
'id'=>'salesprogress:200a53bf6d2bbbfe' //fill a valid salesprogress id to set proper sales progress
),
"custom_fields" => [["voorstel_diensten"=>implode("-",$online_marketing_check)]],
);
return array_replace_recursive($sales_payload, $args);
}
How tu use it:
$a = arrayClone(['status' => 'Closed', 'contact_id' => 5]);
$b = arrayClone(['status' => 'Closed Now', 'contact_id' => 20]);
Hi there i need some help to loop an array of items.
The part that I have repeated needs to be looped in order to get multiple items from the database. At this stage I am only to invoice one item where as users generally purchase a few so i need to run a foreach statement I think. Please excuse my ignorance and lack of understanding, I have tried a series of things but they do not seem to work
$json1 = array(
'Date' => $currentDate->format('Y-m-d\TH:i:s'),
'Customer' => array(
'DisplayID' => $phone
),
'CustomerPurchaseOrderNumber' => $ordID,
'Freight' => '0',
'BalanceDueAmount' => '0.0',
'Status' => 'Closed',
'Lines' => /*$orderDetails,*/ array(
array(
'ShipQuantity' => $ShowDetails['quantity'],
'UnitPrice' => $ShowDetails['unit_price'],
'Total' => $ShowDetails['total_price'],
'Item' => array(
'UID' => $productUID,//itemuid(609400gmkit)
),
'Description' => $productTitle. ' ' .$sizeTitle. ' '
.$colorTitle,
'TaxCode' => array(
'UID' => '7d1f2e99-ffe0-4463-9c29-
61d078b392d3'//taxcodeuid(GST)
)
)
),
'Freight' => $shippingprice,//if dg then $10 otherwise $0 unless below
$100
'ShippingMethod' => $ShippingMethod,// if dg the 'MyFreight' otherwise
'transdirect'
);
The portion that i need to loop is as follows :
array(
'ShipQuantity' => $ShowDetails['quantity'],
'UnitPrice' => $ShowDetails['unit_price'],
'Total' => $ShowDetails['total_price'],
'Item' => array(
'UID' => '27d56af8-d3d6-4f0a-b71b-
4586fffbd63a'//itemuid(609400gmkit)
),
'Description' => $productTitle. ' ' .$sizeTitle. ' '
.$colorTitle,
'TaxCode' => array(
'UID' => '7d1f2e99-ffe0-4463-9c29-
61d078b392d3'//taxcodeuid(GST)
)
)*/
I have some difficulties to merge many multidimensional array in php. I tried to do it by many way, but each time, I don't get the result wanted. I tried with array_merge(array_unique,...) and in different post I found a way with array_map, but I don't understand everything...
I can have many multi array like below:
array(
(int) 0 => array(
'User' => array(
'username' => 'testje',
'firstname' => 'jean',
'lastname' => 'test'
),
'Calendar' => array(
'period' => 'AM'
),
'Shift' => array(
'name' => 'HV',
'color' => '#b7fa00'
),
'Team' => array(
'name' => 'Proxy_B28'
)
),
(int) 1 => array(
'User' => array(
'username' => 'testje',
'firstname' => 'jean',
'lastname' => 'test'
),
'Calendar' => array(
'period' => 'PM'
),
'Shift' => array(
'name' => 'HV',
'color' => '#b7fa00'
),
'Team' => array(
'name' => 'Proxy_B28'
)
)
)
And I would like to get this kind of array :
array(
'User' => array(
'username' => 'testje',
'firstname' => 'jean',
'lastname' => 'test'
),
'Calendar' => array(
'period' => 'Full day'
),
'Shift' => array(
'name' => 'HV',
'color' => '#b7fa00'
),
'Team' => array(
'name' => 'Proxy_B28'
)
)
Do you have some advices to give me to get this result ?
Thank you very much !
I don't know if the best solution but it seems to work like this, and fastly :
foreach ($users as $k=>$v){
//$r[$k] = array_merge($v,$users[$k]);
//$unique[] = array_map("unserialize", array_unique(array_map("serialize", $users[$k])));
$s[$k] = array(
'username' => $v['User']['username'],
'team' => $v['Team']['name'],
'period' => $v['Calendar']['period']
);
if ($k > 0) {
if (in_array($v['User']['username'],$s[$k])) {
unset($s[$k-1]);
$s[$k] = array(
'username' => $v['User']['username'],
'team' => $v['Team']['name'],
'period' => "FD"
);
}
}
}
Do you have another idea or this one is enough good ?
thank you !
I have this code: http://pastebin.com/iFwyKM7G
Inside an event-observer class which executes after the customer registered. It creates an order automatically and it works for simple products. However I cannot figure out for the life of me how to make it work with Bundled product!
How can I make this work with a bundled product?
I DID IT!
I changed my code to the following:
$customer = Mage::getSingleton('customer/customer')->load($observer->getCustomer()->getId());
$session = Mage::getSingleton('adminhtml/session_quote');
$order_create_model = Mage::getSingleton('adminhtml/sales_order_create');
Mage::log($customer->debug(), null, 'toszodj_meg.log');
//$transaction = Mage::getModel('core/resource_transaction');
$storeId = $customer->getStoreId();
Mage::log($customer->getDefaultBillingAddress()->debug(), null, 'toszodj_meg.log');
$reservedOrderId = Mage::getSingleton('eav/config')->getEntityType('order')->fetchNewIncrementId($storeId);
$session->setCustomerId((int) $customer->getId());
$session->setStoreId((int) $storeId);
$orderData = array(
'session' => array(
'customer_id' => $customer->getId(),
'store_id' => $storeId,
),
'payment' => array(
'method' => 'banktransfer',
'po_number' => (string) '-',
),
// 123456 denotes the product's ID value
'add_products' =>array(
'2' => array(
'qty' => 1,
'bundle_option' => array(
2 => 2,
1 => 1,
),
'bundle_option_qty' => array(
2 => 1,
1 => 1,
),
),
),
'order' => array(
'currency' => 'EUR',
'account' => array(
'group_id' => $customer->getGroupId(),
'email' => (string) $customer->getEmail(),
),
'comment' => array('customer_note' => 'API ORDER'),
'send_confirmation' => 1,
'shipping_method' => 'flatrate_flatrate',
'billing_address' => array(
'customer_address_id' => $customer->getDefaultBillingAddress()->getEntityId(),
'prefix' => $customer->getDefaultBillingAddress()->getPrefix(),
'firstname' => $customer->getDefaultBillingAddress()->getFirstname(),
'middlename' => $customer->getDefaultBillingAddress()->getMiddlename(),
'lastname' => $customer->getDefaultBillingAddress()->getLastname(),
'suffix' => $customer->getDefaultBillingAddress()->getSuffix(),
'company' => $customer->getDefaultBillingAddress()->getCompany(),
'street' => $customer->getDefaultBillingAddress()->getStreet(),
'city' => $customer->getDefaultBillingAddress()->getCity(),
'country_id' => $customer->getDefaultBillingAddress()->getCountryId(),
'region' => $customer->getDefaultBillingAddress()->getRegion(),
'region_id' => $customer->getDefaultBillingAddress()->getRegionId(),
'postcode' => $customer->getDefaultBillingAddress()->getPostcode(),
'telephone' => $customer->getDefaultBillingAddress()->getTelephone(),
'fax' => $customer->getDefaultBillingAddress()->getFax(),
),
'shipping_address' => array(
'customer_address_id' => $customer->getDefaultShippingAddress()->getEntityId(),
'prefix' => $customer->getDefaultShippingAddress()->getPrefix(),
'firstname' => $customer->getDefaultShippingAddress()->getFirstname(),
'middlename' => $customer->getDefaultShippingAddress()->getMiddlename(),
'lastname' => $customer->getDefaultShippingAddress()->getLastname(),
'suffix' => $customer->getDefaultShippingAddress()->getSuffix(),
'company' => $customer->getDefaultShippingAddress()->getCompany(),
'street' => $customer->getDefaultShippingAddress()->getStreet(),
'city' => $customer->getDefaultShippingAddress()->getCity(),
'country_id' => $customer->getDefaultShippingAddress()->getCountryId(),
'region' => $customer->getDefaultShippingAddress()->getRegion(),
'region_id' => $customer->getDefaultShippingAddress()->getRegionId(),
'postcode' => $customer->getDefaultShippingAddress()->getPostcode(),
'telephone' => $customer->getDefaultShippingAddress()->getTelephone(),
'fax' => $customer->getDefaultShippingAddress()->getFax(),
),
),
);
$order_create_model->importPostData($orderData['order']);
$order_create_model->getBillingAddress();
$order_create_model->setShippingAsBilling(true);
$order_create_model->addProducts($orderData['add_products']);
$order_create_model->collectShippingRates();
$order_create_model->getQuote()->getPayment()->addData($orderData['payment']);
$order_create_model
->initRuleData()
->saveQuote();
$order_create_model->getQuote()->getPayment()->addData($orderData['payment']);
$order_create_model->setPaymentData($orderData['payment']);
$order_create_model
->importPostData($orderData['order'])
->createOrder();
$session->clear();
Mage::unregister('rule_data');
Mage::log('Order Successfull', null, 'siker_bammer.log');
And it works! thought the customer doesn't get notified. which iam trying to figure out now.
I am trying to find a way to refund payments using Authorize.net's AIM API. I found sample code located here: https://github.com/stymiee/Authorize.Net-XML. Here is the code that I am using from the sample:
require('../../config.inc.php');
require('../../AuthnetXML.class.php');
$xml = new AuthnetXML(AUTHNET_LOGIN, AUTHNET_TRANSKEY, AuthnetXML::USE_DEVELOPMENT_SERVER);
$xml->createTransactionRequest(array(
'refId' => rand(1000000, 100000000),
'transactionRequest' => array(
'transactionType' => 'refundTransaction',
'amount' => 5,
'payment' => array(
'creditCard' => array(
'cardNumber' => 'XXXX1111',
'expirationDate' => '122016'
)
),
'authCode' => '2165668159'
),
));
I keep getting an error message saying that the card code is missing. Any thoughts on what is missing to allow a refund to go through?
NEW CODE:
$xml = new AuthnetXML(AUTHNET_LOGIN, AUTHNET_TRANSKEY);
$xml->createTransactionRequest(array(
'refId' => rand(1000000, 100000000),
'transactionRequest' => array(
'transactionType' => 'refundTransaction',
'amount' => 1.00,
'payment' => array(
'creditCard' => array(
'cardNumber' => 'XXXX1014',
'expirationDate' => '122025',
)
),
'refTransId' => '4928163616',
),
));
$xml = new AuthnetXML(AUTHNET_LOGIN, AUTHNET_TRANSKEY);
$xml->createTransactionRequest(array(
'refId' => rand(1000000, 100000000),
'transactionRequest' => array(
'transactionType' => 'refundTransaction',
'amount' => 1.00,
'payment' => array(
'creditCard' => array(
'cardNumber' => 'XXXX1014',
'expirationDate' => '122025',
)
),
'refTransId' => '4928163616',
'transactionSettings' => array(
'setting' => array(
0 => array(
'settingName' => 'emailCustomer',
'settingValue' => 'true'
),
)
),
),
));