如何定制PayPal的结账页面(PayPal PHP SDK)

如何定制PayPal的结账页面(PayPal PHP SDK),php,paypal,Php,Paypal,我正在使用开发人员文档中建议的PayPal PHP SDK。我当前正在运行此代码: 我只是想更改品牌名称并添加徽标,但我不知道如何实现这一点。由于PayPal更新了他们的设计,您可以在配置文件设置中进行的设计更改将不再有效 要更改设计,您需要先创建一个WebProfile: // Create the WebProfile $presentation = new Presentation(); $presentation->setLogoImage("http:/

我正在使用开发人员文档中建议的PayPal PHP SDK。我当前正在运行此代码:


我只是想更改品牌名称并添加徽标,但我不知道如何实现这一点。

由于PayPal更新了他们的设计,您可以在配置文件设置中进行的设计更改将不再有效

要更改设计,您需要先创建一个WebProfile:

    // Create the WebProfile
    $presentation = new Presentation();
    $presentation->setLogoImage("http://www.yeowza.com/favico.ico")
        ->setBrandName("YeowZa! Paypal")
        ->setLocaleCode("US");
    $inputFields = new InputFields();
    $inputFields->setAllowNote(true)
        ->setNoShipping(1)
        ->setAddressOverride(0);
    $webProfile = new WebProfile();
    $webProfile->setName("YeowZa! T-Shirt Shop" . uniqid())
        ->setPresentation($presentation)
        ->setInputFields($inputFields);
    try {
        $createdProfile = $webProfile->create($paypal);
        $createdProfileID = json_decode($createdProfile);
        $profileid = $createdProfileID->id;
    } catch(PayPal\Exception\PayPalConnectionException $pce) {
        echo '<pre>',print_r(json_decode($pce->getData())),"</pre>";
        exit;
    }
//创建WebProfile
$presentation=新演示文稿();
$presentation->setLogoImage(“http://www.yeowza.com/favico.ico")
->setBrandName(“YeowZa!Paypal”)
->setLocaleCode(“美国”);
$inputFields=新的inputFields();
$inputFields->setAllowNote(真)
->setNoShipping(1)
->setAddressOverride(0);
$webProfile=新的webProfile();
$webProfile->setName(“YeowZa!T恤店”.uniqid())
->setPresentation($presentation)
->setInputFields($inputFields);
试一试{
$createdProfile=$webProfile->create($paypal);
$createdProfileID=json_decode($createdProfile);
$profileid=$createdProfileID->id;
}捕获(PayPal\Exception\PayPalConnectionException$pce){
echo“”,print_r(json_decode($pce->getData()),“”;
        // Create the Payment       
    $product = $_POST['product'];
    $price = 4;
    $shipping  = 2;
    $total = $price + $shipping;

    $payer = new Payer(); 
    $payer->setPaymentMethod("paypal");

    $item1 = new Item();
    $item1->setName('Ground Coffee 40 oz') ->setCurrency('EUR') ->setQuantity(1) ->setSku("123123")->setPrice(6.5); // Similar to `item_number` in Classic API 
    $item2 = new Item();
    $item2->setName('Granola bars') ->setCurrency('EUR') ->setQuantity(1) ->setSku("321321")->setPrice(1.5); // Similar to `item_number` in Classic API  
    $itemList = new ItemList(); 
    $itemList->setItems(array($item1, $item2));

    $details = new Details(); 
    $details->setShipping(1.2) ->setTax(1.3) ->setSubtotal(8);

    $amount = new Amount();
    $amount->setCurrency("EUR") ->setTotal(10.5) ->setDetails($details);

    $transaction = new Transaction();
    $transaction->setAmount($amount)->setItemList($itemList)->setDescription("Payment description")->setInvoiceNumber(uniqid());

    $baseUrl = "http://localhost/abiunity/test.php"; 
    $redirectUrls = new RedirectUrls(); 
    $redirectUrls->setReturnUrl($baseUrl."?success=true")->setCancelUrl($baseUrl."?success=false");

    $payment = new Payment(); 
    $payment->setExperienceProfileId($profileid)->setIntent("sale") ->setPayer($payer) ->setRedirectUrls($redirectUrls) ->setTransactions(array($transaction));
    //$request = clone $payment;

    try {
        $payment->create($paypal);
        $approvalUrl = $payment->getApprovalLink();
        header("Location:".$approvalUrl);
        exit;
    } catch(PayPal\Exception\PayPalConnectionException $pce) {
        echo '<pre>',print_r(json_decode($pce->getData())),"</pre>";
        exit;
    }
出口 }
创建的配置文件的ID存储在$profileid中。此ID需要通过设置。如果创建付款,请设置ExperienceProfileId($profileid)

//创建付款
$product=$_POST['product'];
$price=4;
$shipping=2;
$total=$price+$shipping;
$payer=新的付款人();
$payer->setPaymentMethod(“paypal”);
$item1=新项目();
$item1->setName('磨咖啡40盎司')->setCurrency('EUR')->setQuantity(1)->setku(“123123”)->setPrice(6.5);//类似于经典API中的“项目编号”
$item2=新项目();
$item2->setName('Granola条')->setCurrency('EUR')->setQuantity(1)->setku(“321321”)->setPrice(1.5);//类似于经典API中的“项目编号”
$itemList=新的itemList();
$itemList->setItems(数组($item1,$item2));
$details=新的详细信息();
$details->setShipping(1.2)->setTax(1.3)->setSubtotal(8);
$amount=新金额();
$amount->setCurrency(“欧元”)->setTotal(10.5)->setDetails($details);
$transaction=新事务();
$transaction->setAmount($amount)->setItemList($itemList)->setDescription(“付款说明”)->setInvoiceNumber(uniqid());
$baseUrl=”http://localhost/abiunity/test.php"; 
$redirectUrls=新的重定向URL();
$redirectUrls->setReturnUrl($baseUrl。“?success=true”)->setCancelUrl($baseUrl。“?success=false”);
$payment=新付款();
$payment->setExperienceProfileId($profileid)->setIntent(“销售”)->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(数组($transaction));
//$request=clone$payment;
试一试{
$payment->create($paypal);
$approvalUrl=$payment->getApprovalLink();
标题(“位置:.$approvalUrl”);
出口
}捕获(PayPal\Exception\PayPalConnectionException$pce){
echo“”,print_r(json_decode($pce->getData()),“”;
        // Create the Payment       
    $product = $_POST['product'];
    $price = 4;
    $shipping  = 2;
    $total = $price + $shipping;

    $payer = new Payer(); 
    $payer->setPaymentMethod("paypal");

    $item1 = new Item();
    $item1->setName('Ground Coffee 40 oz') ->setCurrency('EUR') ->setQuantity(1) ->setSku("123123")->setPrice(6.5); // Similar to `item_number` in Classic API 
    $item2 = new Item();
    $item2->setName('Granola bars') ->setCurrency('EUR') ->setQuantity(1) ->setSku("321321")->setPrice(1.5); // Similar to `item_number` in Classic API  
    $itemList = new ItemList(); 
    $itemList->setItems(array($item1, $item2));

    $details = new Details(); 
    $details->setShipping(1.2) ->setTax(1.3) ->setSubtotal(8);

    $amount = new Amount();
    $amount->setCurrency("EUR") ->setTotal(10.5) ->setDetails($details);

    $transaction = new Transaction();
    $transaction->setAmount($amount)->setItemList($itemList)->setDescription("Payment description")->setInvoiceNumber(uniqid());

    $baseUrl = "http://localhost/abiunity/test.php"; 
    $redirectUrls = new RedirectUrls(); 
    $redirectUrls->setReturnUrl($baseUrl."?success=true")->setCancelUrl($baseUrl."?success=false");

    $payment = new Payment(); 
    $payment->setExperienceProfileId($profileid)->setIntent("sale") ->setPayer($payer) ->setRedirectUrls($redirectUrls) ->setTransactions(array($transaction));
    //$request = clone $payment;

    try {
        $payment->create($paypal);
        $approvalUrl = $payment->getApprovalLink();
        header("Location:".$approvalUrl);
        exit;
    } catch(PayPal\Exception\PayPalConnectionException $pce) {
        echo '<pre>',print_r(json_decode($pce->getData())),"</pre>";
        exit;
    }
出口 }

我希望这能帮助一些人并节省一点时间:)

由于PayPal更新了他们的设计,您可以在配置文件设置中进行的设计更改将不再有效

要更改设计,您需要先创建一个WebProfile:

    // Create the WebProfile
    $presentation = new Presentation();
    $presentation->setLogoImage("http://www.yeowza.com/favico.ico")
        ->setBrandName("YeowZa! Paypal")
        ->setLocaleCode("US");
    $inputFields = new InputFields();
    $inputFields->setAllowNote(true)
        ->setNoShipping(1)
        ->setAddressOverride(0);
    $webProfile = new WebProfile();
    $webProfile->setName("YeowZa! T-Shirt Shop" . uniqid())
        ->setPresentation($presentation)
        ->setInputFields($inputFields);
    try {
        $createdProfile = $webProfile->create($paypal);
        $createdProfileID = json_decode($createdProfile);
        $profileid = $createdProfileID->id;
    } catch(PayPal\Exception\PayPalConnectionException $pce) {
        echo '<pre>',print_r(json_decode($pce->getData())),"</pre>";
        exit;
    }
//创建WebProfile
$presentation=新演示文稿();
$presentation->setLogoImage(“http://www.yeowza.com/favico.ico")
->setBrandName(“YeowZa!Paypal”)
->setLocaleCode(“美国”);
$inputFields=新的inputFields();
$inputFields->setAllowNote(真)
->setNoShipping(1)
->setAddressOverride(0);
$webProfile=新的webProfile();
$webProfile->setName(“YeowZa!T恤店”.uniqid())
->setPresentation($presentation)
->setInputFields($inputFields);
试一试{
$createdProfile=$webProfile->create($paypal);
$createdProfileID=json_decode($createdProfile);
$profileid=$createdProfileID->id;
}捕获(PayPal\Exception\PayPalConnectionException$pce){
echo“”,print_r(json_decode($pce->getData()),“”;
        // Create the Payment       
    $product = $_POST['product'];
    $price = 4;
    $shipping  = 2;
    $total = $price + $shipping;

    $payer = new Payer(); 
    $payer->setPaymentMethod("paypal");

    $item1 = new Item();
    $item1->setName('Ground Coffee 40 oz') ->setCurrency('EUR') ->setQuantity(1) ->setSku("123123")->setPrice(6.5); // Similar to `item_number` in Classic API 
    $item2 = new Item();
    $item2->setName('Granola bars') ->setCurrency('EUR') ->setQuantity(1) ->setSku("321321")->setPrice(1.5); // Similar to `item_number` in Classic API  
    $itemList = new ItemList(); 
    $itemList->setItems(array($item1, $item2));

    $details = new Details(); 
    $details->setShipping(1.2) ->setTax(1.3) ->setSubtotal(8);

    $amount = new Amount();
    $amount->setCurrency("EUR") ->setTotal(10.5) ->setDetails($details);

    $transaction = new Transaction();
    $transaction->setAmount($amount)->setItemList($itemList)->setDescription("Payment description")->setInvoiceNumber(uniqid());

    $baseUrl = "http://localhost/abiunity/test.php"; 
    $redirectUrls = new RedirectUrls(); 
    $redirectUrls->setReturnUrl($baseUrl."?success=true")->setCancelUrl($baseUrl."?success=false");

    $payment = new Payment(); 
    $payment->setExperienceProfileId($profileid)->setIntent("sale") ->setPayer($payer) ->setRedirectUrls($redirectUrls) ->setTransactions(array($transaction));
    //$request = clone $payment;

    try {
        $payment->create($paypal);
        $approvalUrl = $payment->getApprovalLink();
        header("Location:".$approvalUrl);
        exit;
    } catch(PayPal\Exception\PayPalConnectionException $pce) {
        echo '<pre>',print_r(json_decode($pce->getData())),"</pre>";
        exit;
    }
出口 }
创建的配置文件的ID存储在$profileid中。此ID需要通过设置。如果创建付款,请设置ExperienceProfileId($profileid)

//创建付款
$product=$_POST['product'];
$price=4;
$shipping=2;
$total=$price+$shipping;
$payer=新的付款人();
$payer->setPaymentMethod(“paypal”);
$item1=新项目();
$item1->setName('磨咖啡40盎司')->setCurrency('EUR')->setQuantity(1)->setku(“123123”)->setPrice(6.5);//类似于经典API中的“项目编号”
$item2=新项目();
$item2->setName('Granola条')->setCurrency('EUR')->setQuantity(1)->setku(“321321”)->setPrice(1.5);//类似于经典API中的“项目编号”
$itemList=新的itemList();
$itemList->setItems(数组($item1,$item2));
$details=新的详细信息();
$details->setShipping(1.2)->setTax(1.3)->setSubtotal(8);
$amount=新金额();
$amount->setCurrency(“欧元”)->setTotal(10.5)->setDetails($details);
$transaction=新事务();
$transaction->setAmount($amount)->setItemList($itemList)->setDescription(“付款说明”)->setInvoiceNumber(uniqid());
$baseUrl=”http://localhost/abiunity/test.php"; 
$redirectUrls=新的重定向URL();
$redirectUrls->setReturnUrl($baseUrl。“?success=true”)->setCancelUrl($baseUrl。“?success=false”);
$payment=新付款();
$payment->setExperienceProfileId($profileid)->setIntent(“销售”)->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(数组($transaction));
//$request=clone$payment;
试一试{
$payment->create($paypal);
$approvalUrl=$payment->getApprovalLink();