douxian6260
douxian6260
2017-02-12 21:35

使用PayPal iOS SDK与WooCommerce

I am working on iOS app using XCode 8.2.1 and Swift 3.0 for a WooCommerce Store website.

What I am trying to do is to allow the user to pay for the order using PayPal iOS SDK inside the app then after receiving the payment success confirmation from the SDK programatically add the order to WooCommerce as paid using PayPal without the need to login to wordpress and proceed to checkout by the user, how to achieve this approach?

Here is my code to create the order on WooCommerce:-

try {
    $api = WC()->api->WC_API_Orders;
    $orderData = $api->create_order($this->data);
    $order = $orderData["order"];
} catch (Exception $e) {
    error_log("Caught $e");
}

Here is the swift code from the paypal ios sdk once the payment succeeded:-

func payPalPaymentViewController(_ paymentViewController: PayPalPaymentViewController, didComplete completedPayment: PayPalPayment) {
    print("PayPal Payment Success !")
    paymentViewController.dismiss(animated: true, completion: { () -> Void in
        // send completed confirmaion to your server
        print("Here is your proof of payment:

\(completedPayment.confirmation)

Send this to your server for confirmation and fulfillment.")

        self.resultText = completedPayment.description
        self.showSuccess()
    })
}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答