diff --git a/examples/demos/web.php b/examples/demos/web.php index fdeccd4..dad5f0e 100644 --- a/examples/demos/web.php +++ b/examples/demos/web.php @@ -4,6 +4,7 @@ $array = array( 'doWebPayment', 'fullWebPayment', + 'paypalExpressCheckout', 'widgetPayment', 'getWebPaymentDetails' ); @@ -14,6 +15,7 @@ $links .= ( 'doWebPayment'==$selected ) ? "doWebPayment (light) - " : "doWebPayment (light) - "; $links .= ( 'fullWebPayment'==$selected ) ? "doWebPayment (full) - " : "doWebPayment (full) - "; $links .= ( 'widgetPayment'==$selected ) ? "doWebPayment (advanced widget) - " : "doWebPayment (advanced widget) - "; + $links .= ( 'paypalExpressCheckout'==$selected ) ? "Paypal Express Checkout - " : "Paypal Express Checkout - "; $links .= ( 'getWebPaymentDetails'==$selected ) ? "getWebPaymentDetails" : "getWebPaymentDetails"; $links .= ''; @@ -181,6 +183,60 @@ function sessionUpdated(token){ document.getElementById('widgetPaymentForm').style.display="none"; Payline.Api.show(); } + + function showStateFunction(state) { + if ("PAYMENT_METHODS_LIST_FAST_CHECKOUT" == state.state) { + // specific process if needed + } + if ("PAYMENT_TRANSITIONAL_FAST_CHECKOUT" == state.state) { + var buyer = Payline.Api.getBuyerFastCheckout(); + document.getElementById("paypalBuyerEmail").value = buyer.email; + document.getElementById("paypalBuyerFirstName").value = buyer.firstName; + document.getElementById("paypalBuyerLastName").value = buyer.lastName; + document.getElementById("paypalBuyerStreet1").value = buyer.street1; + document.getElementById("paypalBuyerStreet2").value = buyer.street2; + document.getElementById("paypalBuyerZipcode").value = buyer.zipCode; + document.getElementById("paypalBuyerCity").value = buyer.cityName; + document.getElementById("paypalBuyerCountry").value = buyer.country; + } + if ("PAYMENT_SUCCESS" == state.state) { + // specific process if needed + } + } + + function finalizeExpressCheckout(token){ + var shippingOption = document.getElementsByName('shippingOption'); + var shippingCost = 1; + for (var i = 0, len = shippingOption.length; i < len; i++) { + if(shippingOption[i].checked){ + shippingCost = document.getElementsByName('shippingOption')[i].value; + } + } + var finalPaymentAmount = parseInt(shippingCost)+parseInt(document.getElementById("paypalExpressCheckoutAmount").value); + + var datasPayline = { + 'payment':{ + 'amount':finalPaymentAmount, + },'order':{ + 'amount':finalPaymentAmount, + },'buyer':{ + 'shippingAddress':{ + 'lastName':document.getElementById('paypalBuyerLastName').value, + 'firstName':document.getElementById('paypalBuyerFirstName').value, + 'street1':document.getElementById('paypalBuyerStreet1').value, + 'street2':document.getElementById('paypalBuyerStreet2').value, + 'cityName':document.getElementById('paypalBuyerCity').value, + 'zipCode':document.getElementById('paypalBuyerZipcode').value, + 'country':document.getElementById('paypalBuyerCountry').value + } + } + }; + Payline.Api.updateWebpaymentData(token, datasPayline, function (response) { + // TODO + }); + Payline.Api.finalizeFastCheckout(); + } + diff --git a/examples/web/paypalExpressCheckout.php b/examples/web/paypalExpressCheckout.php new file mode 100644 index 0000000..2aab066 --- /dev/null +++ b/examples/web/paypalExpressCheckout.php @@ -0,0 +1,205 @@ +addOrderDetail($item1); + + $item2 = array(); + $item2['ref'] = $_SESSION['orderDetailRef2']; + $item2['price'] = $_SESSION['orderDetailPrice2']; + $item2['quantity'] = $_SESSION['orderDetailQuantity2']; + $item2['comment'] = $_SESSION['orderDetailComment2']; + $item2['category'] = $_SESSION['orderDetailCategory2']; + $item2['brand'] = $_SESSION['orderDetailBrand2']; + $item2['subcategory1'] = $_SESSION['orderDetailSubcategory1_2']; + $item2['subcategory2'] = $_SESSION['orderDetailSubcategory2_2']; + $item2['additionalData'] = $_SESSION['orderDetailAdditionalData2']; + $item2['taxRate'] = $_SESSION['orderDetailTaxRate2']; + $payline->addOrderDetail($item2); + + // CONTRACT NUMBERS + $array['payment']['contractNumber'] = $_POST['paypalContractNumber']; + $contracts = explode(";",$_POST['paypalContractNumber']); + $array['contracts'] = $contracts; + $array['secondContracts'] = null; + $array['walletContracts'] = null; + + // URLS + $array['notificationURL'] = $_SESSION['NOTIFICATION_URL']; + $array['returnURL'] = $_SESSION['RETURN_URL']; + $array['cancelURL'] = $_SESSION['CANCEL_URL']; + + // options + $array['customPaymentPageCode'] = $_SESSION['CUSTOM_PAYMENT_PAGE_CODE']; + $array['customPaymentTemplateURL'] = $_SESSION['CUSTOM_PAYMENT_TEMPLATE_URL']; + $array['languageCode'] = $_SESSION['LANGUAGE_CODE']; + + // BUYER + /* + $array['buyer']['legalStatus'] = $_SESSION['buyerLegalStatus']; + $array['buyer']['title'] = $_SESSION['buyerTitle']; + $array['buyer']['lastName'] = $_SESSION['buyerLastName']; + $array['buyer']['firstName'] = $_SESSION['buyerFirstName']; + $array['buyer']['email'] = $_SESSION['buyerEmail']; + $array['buyer']['mobilePhone'] = $_SESSION['mobilePhone']; + $array['buyer']['customerId'] = $_SESSION['customerId']; + $array['buyer']['accountCreateDate'] = $_SESSION['buyerAccountCreateDate']; + $array['buyer']['accountAverageAmount'] = $_SESSION['buyerAverageAmount']; + $array['buyer']['accountOrderCount'] = $_SESSION['buyerOrderCount']; + $array['buyer']['walletId'] = $_SESSION['buyerWalletId']; + $array['buyer']['walletDisplayed'] = $_SESSION['buyerWalletDisplayed']; + $array['buyer']['walletSecured'] = $_SESSION['buyerWalletSecured']; + $array['buyer']['walletCardInd'] = $_SESSION['buyerWalletCardInd']; + $array['buyer']['ip'] = $_SESSION['buyerIp']; + $array['buyer']['legalDocument'] = $_SESSION['legalDocument']; + $array['buyer']['birthDate'] = $_SESSION['birthDate']; + $array['buyer']['fingerprintID'] = $_SESSION['fingerprintID']; + + // BILLING ADDRESS + $array['billingAddress']['title'] = $_SESSION['billingAddressTitle']; + $array['billingAddress']['firstName'] = $_SESSION['billingAddressFirstName']; + $array['billingAddress']['lastName'] = $_SESSION['billingAddressLastName']; + $array['billingAddress']['name'] = $_SESSION['billingAddressName']; + $array['billingAddress']['street1'] = $_SESSION['billingAddressStreet1']; + $array['billingAddress']['street2'] = $_SESSION['billingAddressStreet2']; + $array['billingAddress']['county'] = $_SESSION['billingAddressCounty']; + $array['billingAddress']['cityName'] = $_SESSION['billingAddressCity']; + $array['billingAddress']['zipCode'] = $_SESSION['billingAddressZipCode']; + $array['billingAddress']['country'] = $_SESSION['billingAddressCountry']; + $array['billingAddress']['state'] = $_SESSION['billingAddressState']; + $array['billingAddress']['phoneType'] = $_SESSION['billingAddressPhoneType']; + $array['billingAddress']['phone'] = $_SESSION['billingAddressPhone']; + + // SHIPPING ADDRESS + $array['shippingAddress']['title'] = $_SESSION['shippingAddressTitle']; + $array['shippingAddress']['firstName'] = $_SESSION['shippingAddressFirstName']; + $array['shippingAddress']['lastName'] = $_SESSION['shippingAddressLastName']; + $array['shippingAddress']['name'] = $_SESSION['shippingAddressName']; + $array['shippingAddress']['street1'] = $_SESSION['shippingAddressStreet1']; + $array['shippingAddress']['street2'] = $_SESSION['shippingAddressStreet2']; + $array['shippingAddress']['county'] = $_SESSION['shippingAddressCounty']; + $array['shippingAddress']['cityName'] = $_SESSION['shippingAddressCity']; + $array['shippingAddress']['zipCode'] = $_SESSION['shippingAddressZipCode']; + $array['shippingAddress']['country'] = $_SESSION['shippingAddressCountry']; + $array['shippingAddress']['state'] = $_SESSION['shippingAddressState']; + $array['shippingAddress']['phoneType'] = $_SESSION['shippingAddressPhoneType']; + $array['shippingAddress']['phone'] = $_SESSION['shippingAddressPhone']; + */ + + // MERCHANT NAME + $array['merchantName'] = $_SESSION['MERCHANT_NAME']; + + // PRIVATE DATA + for($i=1;$i<=8;$i++){ + $privateData = array(); + $privateData['key'] = $_SESSION['pvdKey'.$i] ; + $privateData['value'] = $_SESSION['pvdValue'.$i]; + $payline->addPrivateData($privateData); + } + + // EXECUTE + $response = $payline->doWebPayment($array); + if(isset($response) && $response['result']['code'] == '00000'){ + echo " "; + echo "
"; + } elseif(isset($response)) { + echo 'ERROR : '.$response['result']['code']. ' '.$response['result']['longMessage'].' '; + } +}else{ // back from Paypal pages + ?> +
+ '/> +
+

Information retrieved from Paypal

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+

Choose your shipping option

+
+ + +
+
+ + +
+
+ + +
+
+
+
' data-template='fastcheckout' data-event-didshowstate='showStateFunction'>
+
+ +
+ \ No newline at end of file diff --git a/examples/web/paypalExpressCheckoutForm.php b/examples/web/paypalExpressCheckoutForm.php new file mode 100644 index 0000000..ac192e5 --- /dev/null +++ b/examples/web/paypalExpressCheckoutForm.php @@ -0,0 +1,30 @@ +
+
+

Do Web Payment minimal informations

+
+ + + (required) +
+
+ + + (required) +
+
+ + + (required) +
+
+
+

Paypal informations

+
+ + + (required) +
+
+
+ +