/** * * * @param unknown $pay_key * @param unknown $order_id * * @return unknown */ public function set_paypal_author_specifics($pay_key, $order_id) { global $woocommerce; $this->include_paypal_sdk(); $order = new WC_Order($order_id); // Create request $setPaymentOptionsRequest = new SetPaymentOptionsRequest(new RequestEnvelope("en_US")); $setPaymentOptionsRequest->payKey = $pay_key; if ($this->instapay) { $setPaymentOptionsRequest = $this->set_vendor_items($order, $setPaymentOptionsRequest); } if ($this->debug_me) { foreach ($setPaymentOptionsRequest->receiverOptions as $k) { var_dump($k->invoiceData); } exit; } $setPaymentOptionsRequest->senderOptions = new SenderOptions(); $setPaymentOptionsRequest->senderOptions->requireShippingAddressSelection = true; $service = new AdaptivePaymentsService(); try { $response = $service->SetPaymentOptions($setPaymentOptionsRequest); } catch (Exception $ex) { wc_add_notice(sprintf(__('Error: %s', 'wcvendors'), $ex->getMessage()), 'error'); return false; } $this->logger->error("Received SetPaymentOptionsResponse:"); $ack = strtoupper($response->responseEnvelope->ack); if ($ack != "SUCCESS") { $order->update_status('cancelled', __(sprintf('Error ID: %s. %s', $response->error[0]->errorId, $response->error[0]->message), 'wcvendors')); wc_add_notice(sprintf('Error ID: %s. %s', $response->error[0]->errorId, $response->error[0]->message), 'error'); return false; } return true; }
if ($_POST['headerImageUrl'] != "") { $setPaymentOptionsRequest->displayOptions->headerImageUrl = $_POST['headerImageUrl']; } if ($_POST['businessName'] != "") { $setPaymentOptionsRequest->displayOptions->businessName = $_POST['businessName']; } } /* * ## Creating service wrapper object Creating service wrapper object to make API call and loading Configuration::getAcctAndConfig() returns array that contains credential and config parameters */ $service = new AdaptivePaymentsService(Configuration::getAcctAndConfig()); try { /* wrap API method calls on the service object with a try catch */ $response = $service->SetPaymentOptions($setPaymentOptionsRequest); } catch (Exception $ex) { require_once 'Common/Error.php'; exit; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>PayPal Adaptive Payments - Set Payment Options</title> <link href="Common/sdk.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="Common/sdk_functions.js"></script> </head> <body> <div id="wrapper">
/** * Process the payment and return the result * * @access public * @param int $order_id * @return array */ function process_payment($order_id) { $receiver = array(); $payRequest = new PayRequest(); $order = new WC_Order($order_id); $sub_orders = get_children(array('post_parent' => $order_id, 'post_type' => 'shop_order')); if ($sub_orders) { $sum = 0; foreach ($sub_orders as $key => $order_post) { $seller_id = dokan_get_seller_id_by_order($order_post->ID); $seller_balance = $this->get_seller_net_balance($order_post->ID, $seller_id); $seller_pay_email = dokan_get_seller_withdraw_mail($seller_id); if (false === $seller_pay_email) { $seller_pay_email = get_user_by('id', $seller_id)->user_email; } $receiver[$key] = new Receiver(); $receiver[$key]->amount = $seller_balance; $receiver[$key]->email = $seller_pay_email; $sum += (double) $seller_balance; } if ($this->payment_process == 'chained') { $admin_amount = (string) $order->get_total(); } else { $admin_amount = (string) ((double) $order->get_total() - $sum); } } else { $seller_id = dokan_get_seller_id_by_order($order_id); $seller_balance = $this->get_seller_net_balance($order_id, $seller_id); $seller_pay_email = dokan_get_seller_withdraw_mail($seller_id); if (false === $seller_pay_email) { $seller_pay_email = get_user_by('id', $seller_id)->user_email; } $receiver[0] = new Receiver(); $receiver[0]->amount = $seller_balance; $receiver[0]->email = $seller_pay_email; if ($this->payment_process == 'chained') { if ($this->single_mode == 'yes') { $admin_amount = (string) ((double) $order->get_total() - (double) $seller_balance); $receiver[0]->amount = (string) $order->get_total(); } else { $admin_amount = (string) $order->get_total(); } } else { $admin_amount = (string) ((double) $order->get_total() - (double) $seller_balance); } } $count = count($receiver); if ($admin_amount > 0) { $receiver[$count] = new Receiver(); $receiver[$count]->amount = $admin_amount; $receiver[$count]->email = $this->pa_admin_email; } if ($this->payment_process == 'chained') { if ($this->single_mode == 'yes') { $receiver[0]->primary = "true"; } else { $receiver[$count]->primary = "true"; } } $this->add_log('Payment Process: ' . $this->payment_process . ' ------ Reciever list' . print_r($receiver, true) . '...'); $receiverList = new ReceiverList($receiver); $payRequest->receiverList = $receiverList; $requestEnvelope = new RequestEnvelope("en_US"); $payRequest->requestEnvelope = $requestEnvelope; $payRequest->actionType = "PAY"; $payRequest->cancelUrl = esc_url($order->get_cancel_order_url()); $payRequest->returnUrl = esc_url($this->get_return_url($order)); $payRequest->currencyCode = get_woocommerce_currency(); $payRequest->ipnNotificationUrl = $this->notify_url; if ('yes' == $this->testmode) { $sdkConfig = array("mode" => "sandbox", "acct1.UserName" => $this->test_appuser, "acct1.Password" => $this->test_apppass, "acct1.Signature" => $this->test_appsig, "acct1.AppId" => "APP-80W284485P519543T"); } else { $sdkConfig = array("mode" => "live", "acct1.UserName" => $this->appuser, "acct1.Password" => $this->apppass, "acct1.Signature" => $this->appsig, "acct1.AppId" => $this->appid); } $adaptivePaymentsService = new AdaptivePaymentsService($sdkConfig); $payResponse = $adaptivePaymentsService->Pay($payRequest); if ($payResponse->payKey) { $shippingAddressInfo = new ShippingAddressInfo(); $shippingAddressInfo->addresseeName = $order->billing_first_name . ' ' . $order->billing_last_name; $shippingAddressInfo->street1 = $order->billing_address_1; $shippingAddressInfo->street2 = $order->billing_address_2; $shippingAddressInfo->city = $order->billing_city; $shippingAddressInfo->zip = $order->billing_postcode; $shippingAddressInfo->state = $this->get_paypal_state($order->billing_country, $order->billing_state); $shippingAddressInfo->country = $order->billing_country; if ('yes' == $this->send_shipping) { $shippingAddressInfo->addresseeName = $order->shipping_first_name . ' ' . $order->shipping_last_name; $shippingAddressInfo->street1 = $order->shipping_address_1; $shippingAddressInfo->street2 = $order->shipping_address_2; $shippingAddressInfo->city = $order->shipping_city; $shippingAddressInfo->zip = $order->shipping_postcode; $shippingAddressInfo->state = $this->get_paypal_state($order->shipping_country, $order->shipping_state); $shippingAddressInfo->country = $order->shipping_country; } $so = new SenderOptions(); $so->shippingAddress = $shippingAddressInfo; $re = new RequestEnvelope('en_US'); $setPaymentOptionsRequest = new SetPaymentOptionsRequest($re, $payResponse->payKey); $setPaymentOptionsRequest->senderOptions = $so; $paymentOptionRequest = $adaptivePaymentsService->SetPaymentOptions($setPaymentOptionsRequest); } $this->add_log('Payment Response: ' . print_r($payResponse, true)); // update paykey reference to find out update_post_meta($order->id, '_dokan_pap_key', $payResponse->payKey); if ('yes' == $this->testmode) { $paypal_url = "https://www.sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=" . $payResponse->payKey; } else { $paypal_url = "https://www.paypal.com/webscr?cmd=_ap-payment&paykey=" . $payResponse->payKey; } // Return thankyou redirect return array('result' => 'success', 'redirect' => $paypal_url); }