Fórum MOSTRAR PAYPAL NO CHECKOUT DO APP IONIC #602142

01/05/2019

0

Olá galera, Boa tarde!

Estou com um probleminha em Ionic que está quebrando muito minha cabeça por dias.
Método de pagamento do paypal aparece em meu site, mas não aparece no app ionic, o que será? Já tentei de tudo. Esse app faz comunicação via API do Woocommerce, e lá está habilitado a forma de pagamento com PayPal, porém só não aparece no app, já que na página de checkout no meu site, aparece.

Segue o código da página de checkout do app:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import { Component, Inject } from '@angular/core';
import { NavController, NavParams, AlertController, Loading, LoadingController, ToastController, App } from 'ionic-angular';
import { PlacedPage } from '../placed/placed';
import { PaymentGateway } from "../../models/payment-gateway.models";
import { Constants } from "../../models/constants.models";
 
import { WordpressClient } from '../../providers/wordpress-client.service';
import { Global } from '../../providers/global';
import { Subscription } from "rxjs/Subscription";
import { CartItem } from "../../models/cart-item.models";
import { OrderRequest } from "../../models/order-request.models";
import { Address } from "../../models/address.models";
import { ShippingLine } from "../../models/shipping-line.models";
import { UserResponse } from "../../models/user-response.models";
import { OrderResponse } from "../../models/order-response.models";
import { Currency } from "../../models/currency.models";
import { InAppBrowser, InAppBrowserOptions } from '@ionic-native/in-app-browser';
import { sha512 } from 'js-sha512';
import { APP_CONFIG, AppConfig } from '../../app/app.config';
import { OrderUpdateRequest } from '../../models/order-update-request.models';
import { Coupon } from '../../models/coupon.models';
import { HomePage } from '../home/home';
import { TranslateService } from '@ngx-translate/core';
import { Helper } from '../../models/helper.models';
import { ShippingMethod } from '../../models/shipping-method.models';
import { PayPal, PayPalPayment, PayPalConfiguration, PayPalPaymentDetails } from '@ionic-native/paypal';
 
@Component({
    selector: 'page-payment',
    templateUrl: 'payment.html',
    providers: [WordpressClient]
})
 
export class PaymentPage {
    private loading: Loading;
    private loadingShown: Boolean = false;
    private placedPagePushed: Boolean = false;
    private paymentDone: Boolean = false;
    private paymentFailAlerted: Boolean = false;
 
    private subscriptions: Array<Subscription> = [];
    private paymentGateways = new Array<PaymentGateway>();
    private cartItems: Array<CartItem>;
    private selectedPaymentGateway;
    private selectedAddress: Address;
    private orderRequest: OrderRequest;
    private orderId = -1;
    private user: UserResponse;
    private totalItems = 0;
    private total = 0;
    private couponApplied = false;
    private pickupTime = 0;
    private deliveryTime = 0;
    private shippingChargeGlobal: number;
 
    constructor(@Inject(APP_CONFIG) private config: AppConfig, public translate: TranslateService, private iab: InAppBrowser, private toastCtrl: ToastController, public navCtrl: NavController, private navParams: NavParams, private service: WordpressClient, private loadingCtrl: LoadingController, private alertCtrl: AlertController, public appCtrl: App) {
        this.cartItems = this.navParams.get('cart');
        this.totalItems = this.navParams.get('totalItems');
        this.total = this.navParams.get('total');
        this.shippingChargeGlobal = this.navParams.get('shippingChargeGlobal');
 
        let paymentGateways = JSON.parse(window.localStorage.getItem(Constants.PAYMENT_GATEWAYS));
        this.selectedAddress = JSON.parse(window.localStorage.getItem(Constants.SELECTED_ADDRESS));
 
 
        if (paymentGateways != null) {
            for (let pg of paymentGateways) {
                if (pg.enabled && this.paymentImplemented(pg.id)) {
                    this.paymentGateways.push(pg);
                }
            }
        }
    }
 
    ionViewWillLeave() {
        this.subscriptions.forEach((subscription: Subscription) => {
            subscription.unsubscribe();
        });
        this.dismissLoading();
    }
 
    paymentImplemented(id) {
        return id === "pumcp" || id === "payuindia" || id === "cod";
    }
 
    paymentMethod(paymentGateway) {
        this.selectedPaymentGateway = paymentGateway;
    }
 
    placedPage() {
        if (this.selectedPaymentGateway == null) {
            this.translate.get('field_error_payment_method').subscribe(value => {
                this.showToast(value);
            });
        } else {
            this.orderRequest = new OrderRequest();
            this.orderRequest.payment_method = this.selectedPaymentGateway.id ? this.selectedPaymentGateway.id : "cod";
            this.orderRequest.payment_method_title = this.selectedPaymentGateway.title ? this.selectedPaymentGateway.title : "cod";
            this.orderRequest.set_paid = false;
            this.orderRequest.billing = this.selectedAddress;
            this.orderRequest.shipping = this.selectedAddress;
            this.user = JSON.parse(window.localStorage.getItem(Constants.USER_KEY));
            this.orderRequest.customer_id = String(this.user.id);
 
            let selectedShippingMethod: ShippingMethod = JSON.parse(window.localStorage.getItem(Constants.SELECTED_SHIPPING_METHOD));
            if (selectedShippingMethod) {
                let shippingTotal = 0;
                for (let ci of this.cartItems) {
                    if (!ci.product.shipping_cost_use_global && ci.product.shipping_cost != 1)
                        shippingTotal = shippingTotal + ci.product.shipping_cost;
                }
                if (this.shippingChargeGlobal != -1) {
                    shippingTotal = shippingTotal + this.shippingChargeGlobal;
                }
                this.orderRequest.shipping_lines = new Array<ShippingLine>();
                this.orderRequest.shipping_lines.push(new ShippingLine(selectedShippingMethod.method_id, selectedShippingMethod.method_title, String(shippingTotal)));
            }
 
            this.orderRequest.line_items = this.cartItems;
            for (let item of this.orderRequest.line_items) {
                item.product = null;
            }
 
            this.translate.get('order_creating').subscribe(value => {
                this.presentLoading(value);
            });
            let coupon: Coupon = JSON.parse(window.localStorage.getItem(Constants.SELECTED_COUPON));
            let subscription: Subscription = this.service.createOrder(window.localStorage.getItem(Constants.ADMIN_API_KEY), this.orderRequest).subscribe(data => {
                this.orderId = data.id;
                if (coupon) {
                    this.applyCoupon(coupon);
                } else {
                    this.orderPlaced();
                }
            }, err => {
                console.log(err);
                this.dismissLoading();
                let orderId = Helper.extractOrderIdFromError(err);
                if (orderId != -1) {
                    this.orderId = orderId;
                    if (coupon) {
                        this.applyCoupon(coupon);
                    } else {
                        this.orderPlaced();
                    }
                } else {
                    this.translate.get('order_failed').subscribe(value => {
                        this.showToast(value);
                    });
                    this.appCtrl.getRootNav().setRoot(HomePage);
                }
            });
            this.subscriptions.push(subscription);
        }
    }
 
    applyCoupon(coupon) {
        let couponSubs: Subscription = this.service.applyCouponCode(window.localStorage.getItem(Constants.ADMIN_API_KEY), String(this.orderId), coupon.code).subscribe(data => {
            this.couponApplied = true;
            window.localStorage.removeItem(Constants.SELECTED_COUPON);
            this.translate.get('confirm_order_coupon_applied').subscribe(value => {
                this.showToast(value);
            });
            this.orderPlaced();
        }, err => {
            console.log(err);
            this.dismissLoading();
        });
        this.subscriptions.push(couponSubs);
    }
 
    orderPlaced() {
        this.dismissLoading();
        if (this.selectedPaymentGateway.id && this.selectedPaymentGateway.id === "cod") {
            this.clearCart();
            this.navCtrl.setRoot(PlacedPage);
        } else if (this.selectedPaymentGateway.id === "pumcp" || this.selectedPaymentGateway.id === "payuindia") {
            this.initPayUMoney();
        } else {
            this.translate.get('order_placed_cod').subscribe(value => {
                this.showToast(value);
            });
            this.clearCart();
            this.navCtrl.setRoot(PlacedPage);
        }
    }
 
    initPayUMoney() {
        let name = this.user.first_name && this.user.first_name.length ? this.user.first_name : this.user.username;
        let mobile = this.user.username;
        let email = this.user.email;
        let bookingId = String(Math.floor(Math.random() * (99 - 10 + 1) + 10)) + this.orderId;
        let productinf
Kellison Ruan

Kellison Ruan

Responder

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar