Skip to content

Commit

Permalink
Merge pull request #3 from dzung2t/master
Browse files Browse the repository at this point in the history
Added User Profile API support
  • Loading branch information
Roman Sevastyanov committed Aug 3, 2015
2 parents d2475f4 + 7dc4e03 commit 30b86ee
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 56 deletions.
12 changes: 4 additions & 8 deletions src/app/addons/paymentwall/controllers/common/paymentwall.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,19 @@ function modeFrame()
// Payment widget
function modePayment()
{
$rid = $_REQUEST['order_id'];
$orderId = $_SESSION['pw_order_id'];
$orderId = isset($_SESSION['pw_order_id']) && $_SESSION['pw_order_id'] ? $_SESSION['pw_order_id'] : false;
$iframe = '';
$matchOrder = ($rid == $orderId);
$orderInfo = fn_get_order_info($orderId);

if ($matchOrder && $orderInfo) {
if ($orderId && $orderInfo = fn_get_order_info($orderId)) {
// Prepare Widget
$iframe = fn_paymentwall_generateWidget($orderInfo, fn_paymentwall_getPaymentConfigs($orderInfo['payment_id']));
}

// Clear Shopping Cart Session
fn_clear_cart($_SESSION['cart']);
fn_add_breadcrumb('Paymentwall Payment', '#', true);

Tygh::$app['view']->assign('params', array(
'matchOrder' => $matchOrder,
'orderId' => $orderId,
'baseUrl' => fn_url(),
'iframe' => $iframe
Expand Down Expand Up @@ -79,7 +75,7 @@ function orderStatusProcessor($status)
switch ($status) {
case PW_ORDER_STATUS_PROCESSED:
// Order Processed : Clear shopping cart
fn_clear_cart($_SESSION['cart']);
unset($_SESSION['pw_order_id']);
break;
default:
break;
Expand Down
64 changes: 18 additions & 46 deletions src/app/addons/paymentwall/func.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function fn_paymentwall_generateWidget($orderInfo, $paymentInfo, $extraAttr = ar
'integration_module' => 'cs_cart',
'test_mode' => $paymentInfo['test_mode']
),
fn_paymentwall_get_shipping_information($orderInfo)
fn_paymentwall_prepare_user_profile_data($orderInfo)
));

// Generate Widget
Expand Down Expand Up @@ -81,12 +81,9 @@ function fn_paymentwall_handlePingback($configs)
$pingback->getParameter('ref'),
$paymentInfo['test_mode']
));

if (isset($response['error'])) {
var_dump($response['error'], $response['notices']);
}

}

// Update order status: Processed
fn_paymentwall_updateOrderStatus($pingback->getProductId(), PW_ORDER_STATUS_PROCESSED);

Expand Down Expand Up @@ -125,46 +122,6 @@ function fn_paymentwall_getRealPrice($orderInfo)
return $orderInfo['total'] / $coefficient;
}

/**
* Prepare Shipping information
* @param $orderInfo
* @return array
* @internal param $params
*/
function fn_paymentwall_get_shipping_information($orderInfo)
{
return array(
'customer' => array(
'email' => $orderInfo['email'],
'firstname' => $orderInfo['b_firstname'],
'lastname' => $orderInfo['b_lastname'],
'street1' => $orderInfo['b_address'],
'street2' => $orderInfo['b_address_2'],
'city' => $orderInfo['b_city'],
'state' => $orderInfo['b_state'],
'postcode' => $orderInfo['b_zipcode'],
'country' => $orderInfo['b_country'],
'phone' => $orderInfo['b_phone']
),
'shipping_address' => array(
'firstname' => $orderInfo['s_firstname'],
'lastname' => $orderInfo['s_lastname'],
'company' => '', // null
'street1' => $orderInfo['s_address'],
'street2' => $orderInfo['s_address_2'],
'city' => $orderInfo['s_city'],
'state' => $orderInfo['s_state'],
'postcode' => $orderInfo['s_zipcode'],
'country' => $orderInfo['s_country'],
'phone' => $orderInfo['s_phone']
),
'shipping_fee' => array(
'amount' => $orderInfo['shipping_cost'],
'currency' => $orderInfo['secondary_currency']
)
);
}

/**
* @param $orderInfo
* @param $ref
Expand Down Expand Up @@ -194,4 +151,19 @@ function fn_paymentwall_prepare_delivery_confirmation($orderInfo, $ref, $isTest
'shipping_address[firstname]' => $orderInfo['s_firstname'],
'shipping_address[lastname]' => $orderInfo['s_lastname'],
);
}

function fn_paymentwall_prepare_user_profile_data($orderInfo)
{
return array(
'customer[city]' => $orderInfo['b_city'],
'customer[state]' => $orderInfo['b_state'],
'customer[address]' => $orderInfo['b_address'],
'customer[country]' => $orderInfo['b_county'],
'customer[zip]' => $orderInfo['b_zipcode'],
'customer[username]' => $orderInfo['user_id'] ? $orderInfo['user_id'] : $orderInfo['ip_address'],
'customer[firstname]' => $orderInfo['b_firstname'],
'customer[lastname]' => $orderInfo['b_lastname'],
'email' => $orderInfo['email'],
);
}
2 changes: 1 addition & 1 deletion src/app/addons/paymentwall/payments/paymentwall.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
fn_change_order_status($order_info['order_id'], 'O');

// Redirect to widget page
$postUrl = fn_url('paymentwall.payment&order_id=' . $order_info['order_id']);
$postUrl = fn_url('paymentwall.payment');
$_SESSION['pw_order_id'] = $order_info['order_id'];
header("Location: {$postUrl}");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{assign var="checkout" value="checkout"}
{if $params.matchOrder}
{if $params.orderId}
{$params.iframe nofilter}
{script src="js/addons/paymentwall/func.js"}
<script type="text/javascript">
Expand Down

0 comments on commit 30b86ee

Please sign in to comment.