Monday, August 30, 2010

Passing Shipping Info to Paypal Pro with API call doDirectPayment on OpenCart

Problem:
A client of mine wanted to use OpenCart for a shopping cart website and was using PayPal pro to handle the e-commerce. The problem was that the only information OpenCart passed to PayPal was the information needed to process the credit card. This makes sense if you are handling all your shipping things in OpenCart, however in my clients situation, they needed someone else on PayPal to be able to see the shipping information for fulfilling the orders.

Solution:
The PHP file handling the connection to PalPay was only passing some of the data, not all of it. If you look at the file: root/catalog/controller/payment/pp_pro.php, you will see a PHP associative array handling all the data that will be passed to PayPal. (Note: an associative array is where you can hold a lot of data in one container and by using what are called key/value pairs. For instance a key might be something like shoe_size and the value may be something like 12 written in PHP with key => value). I looked into the object holding on the user data and found that just like payment_*** you can use shipping_***. So my setup ended up looking similar to this:

$payment_data = array(
            'METHOD'         => 'DoDirectPayment',
            'VERSION'        => '51.0',
            'USER'           => html_entity_decode($this->config->get('pp_pro_username'), ENT_QUOTES, 'UTF-8'),
            'PWD'            => html_entity_decode($this->config->get('pp_pro_password'), ENT_QUOTES, 'UTF-8'),
            'SIGNATURE'      => html_entity_decode($this->config->get('pp_pro_signature'), ENT_QUOTES, 'UTF-8'),
            'CUSTREF'        => $order_info['order_id'],
            'PAYMENTACTION'  => $payment_type,
            'AMT'            => $this->currency->format($order_info['total'], $order_info['currency'], $order_info['value'], FALSE),
            'CREDITCARDTYPE' => $this->request->post['cc_type'],
            'ACCT'           => str_replace(' ', '', $this->request->post['cc_number']),
            'CARDSTART'      => $this->request->post['cc_start_date_month'] . $this->request->post['cc_start_date_year'],
            'EXPDATE'        => $this->request->post['cc_expire_date_month'] . $this->request->post['cc_expire_date_year'],
            'CVV2'           => $this->request->post['cc_cvv2'],
            'CARDISSUE'      => $this->request->post['cc_issue'],
            'FIRSTNAME'      => $order_info['payment_firstname'],
            'LASTNAME'       => $order_info['payment_lastname'],
            'EMAIL'          => $order_info['email'],
            'PHONENUM'       => $order_info['telephone'],
            'IPADDRESS'      => $this->request->server['REMOTE_ADDR'],
            'STREET'         => $order_info['payment_address_1'],
            'CITY'           => $order_info['payment_city'],
            'STATE'          => ($order_info['payment_iso_code_2'] != 'US') ? $order_info['payment_zone'] : $order_info['payment_zone_code'],
            'ZIP'            => $order_info['payment_postcode'],
            'COUNTRYCODE'    => $order_info['payment_iso_code_2'],
            'CURRENCYCODE'   => $order_info['currency'],
            'DESC'            => 'items being ordered - 127 char limit',
            'SHIPTONAME'     => $order_info['shipping_firstname'] . $order_info['shipping_lastname'],
            'SHIPTOSTREET'     => $order_info['shipping_address_1'],
            'SHIPTOCITY'     => $order_info['shipping_city'],
            'SHIPTOSTATE'     => ($order_info['shipping_iso_code_2'] != 'US') ? $order_info['shipping_zone'] : $order_info['shipping_zone_code'],
            'SHIPTOZIP'         => $order_info['shipping_postcode'],
            'SHIPTOCOUNTRY'     => $order_info['shipping_iso_code_2'],
            'SHIPTOPHONENUM' => $order_info['telephone']
);
Hopefully this will help out some who have had issues with this.

Wednesday, August 25, 2010

Symfony 1.4 - crashing when loading large fixture files

Problem:
I have been trying to load a large fixture file in Symfony but everytime I went to load the fixture using doctrine:load-data, Symfony would crash. I looked at the mySQL tables and found that Symfony had in fact finished loading the fixture, but for some reason had become non-responsive.

Solution:
To allow symfony to load the fixture (whether it crashes due to system resources like PHP memory or an issue with PHP itself), I found that I can control the loading of the fixture by following these simple steps.

  1. Split the fixture into several files (While keeping your table reference in each one)
  2. Load each fixture file 1 at a time (this can be accomplished using doctrine:data-load --append rel/path/to/fixture)
  3. check your tables to ensure data is still being loaded, if you find it has stalled more a good amount of time and nothing has been loaded, you will probably want to look into killing the PHP process (something I wont explain here) and doing some more fixture break downs.
Hopefully this will help some of you who have had the same issue I have been having.

Tuesday, August 24, 2010

Control Loading Order / Sequence of Fixtures in Symfony 1.4

Problem:

I want to split my fixtures into separate files in the fixtures directory but when I try to load the data, I get constraint errors.

Solution:
Symfony has a solution for determining the sequence it should use to load fixtures, that is by placing a number in from of the original file name. I use 1_filename.yml.

Good luck programming.

Friday, August 20, 2010

Apply Smoothing to Video in Spark VideoPlayer or VideoDisplay Component

Problem:
I want to allow smoothing on the video that is being played by a Spark VideoPlayer or VideoDisplay component but those components don't have a property for this.

Solution:
To smooth a video being played by one of these components, you have to access the video object once it is loaded. These components do not provide a smoothing option directly. To determine when a video has loaded, we will detect a state change on the component itself by adding a MediaPlayerStateChangeEvent listener.

MXML:
<s:VideoDisplay id="vid_player" top="0" left="0" right="0" bottom="0" source="video.flv"  mediaPlayerStateChange="checkState(event)" />

AS3 (MXML Alternative) - attach the listener with AS3:
vid_player.addEventListener(MediaPlayerStateChangeEvent.MEDIA_PLAYER_STATE_CHANGE, checkState)

The checkState method will do more to check is the video has successfully loaded.

AS3 - checkState Method:
import org.osmf.events.MediaPlayerStateChangeEvent;
private function checkState(e:MediaPlayerStateChangeEvent):void{
    if(e.state == "playing") 
        vid_player.videoObject.smoothing = true;
}

 If you try to access the videoObject before the "playing" state, you will get a null reference.

Please let me know if you come across any questions with this code.