dongniaocheng3773 2016-10-20 23:10
浏览 315
已采纳

如何自定义PayPal的结账页面(PayPal-PHP-SDK)

I am working with the PayPal-PHP-SDK as suggested in the Developer Docs. I am running this code currently:

http://paypal.github.io/PayPal-PHP-SDK/

I simply want to change the Brand Name and add a Logo, but I don't know how to achieve this.

  • 写回答

1条回答 默认 最新

  • dpjjr42626 2016-10-21 09:49
    关注

    Since PayPal updated their Design the Design changes you can make in the profile Settings wont work anymore.

    To change the Design, you need to create a WebProfile first:

        // 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;
        }
    

    The ID of the created Profile is been stored in $profileid.This ID needs to be set via. setExperienceProfileId($profileid) if you create the payment.

            // 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;
        }
    

    I hope this helps someone and saves a little bit of time :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
    1人已打赏

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。