• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

javascript - 云代码无效功能的back4app问题

[复制链接]
菜鸟教程小白 发表于 2022-12-12 23:54:24 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我的问题是:我必须在带有 conekta 的 iOS 应用程序中实现一些支付,我的服务器在 back4app 中运行得很好,之前我只有云中的 Braintree 功能,现在我已经搬到了科内克塔back4app 调用不断失败 iOS 给了我错误 Invalid function ,我已经从我为 Braintree 的 sintax 中复制了它,我在 Node.js 或 js 方面并不擅长。我用于云的代码:

// Requiring npm module
var braintree = require("braintree");
var conekta = require('conekta');
conekta.api_key = 'key_eYvWV7gSDkNYXsmr';
conekta.api_version = '2.0.0';

//conekta  stuff
// Function for conekta
Parse.Cloud.define("conektaCustomer", function (request, response) {
  var name = request.params.name;
  var email = request.params.email;
  var phone = request.params.phone;
  var card = 'card';
  var token_id = request.params.tokenId;
  var lavado = request.params.total;

  console.log(name + email + phone + card + token_id + lavado);

  var customerID = conekta.Customer.create({
    'name': name,
    'email': [email protected]',
    'phone': phone,
    'payment_methods': [{
      'type': card,
      'token_id': token_id
    }]
  }, function(err, res) {
      console.log(res.toObject());
    });

    order = conekta.Order.create({
    "line_items": [{
        "name": "Lavado",
        "unit_price": lavado,
        "quantity": 12
    }],
    "shipping_lines": [{
        "amount": 0,
        "carrier": "Automozo"
    }],
    "currency": "MXN",
    "customer_info": {
     "customer_id": customerID.id
    },
    "shipping_contact":{
     "phone": customerID.phone,
     "receiver": customerId.name,
     "address": {
       "street1": "Automozo",
       "city": "Monterrey",
       "state": "Nuevo Leon",
       "country": "MX",
       "postal_code": "64630",
       "residential": true
     }
   },
   "amount": lavado,
  "charges":[{
    "payment_method": {
      "token_id": token_id,
      "type": "card"
    }
  }]
}, function(err, res) {
      console.log(res.toObject());
});

});


// Initializing gateway
var gateway = braintree.connect({
  environment: braintree.Environment.Sandbox,
  merchantId: "rw4ty7nn96t8kzcz",
  publicKey: "qd77d84sy3836qbx",
  privateKey: "8fc74c88de4a7b8acf417aadfb92f6c5"
});

// Function for client token generation
Parse.Cloud.define("generateToken", function(request, response) {
  var clientId = request.params.clientId;
  console.log(clientId)
  gateway.clientToken.generate({
     customerId: clientId
  }, function (err, res) {
    if (err) {
      console.log(err);
      response.error(err);
    } else {
      response.success(res.clientToken);
    }
  });
});

// Function for checkout
Parse.Cloud.define("checkout", function (request, response) {
  var nonce = request.params.payment_method_nonce;
  var amountPayed = request.params.amount;
  var clientId = request.params.customerId;
  console.log(clientId);
  console.log(nonce);
  console.log(amountPayed);
  // Use payment method nonce here, for example:
  gateway.transaction.sale({
    amount: amountPayed, // $ 10.00 sale
    paymentMethodNonce: nonce,
    customerId: clientId,
    options: {
      submitForSettlement: true
    }
  }, function (err, result) {
    if (err) {
      response.error(err);
    } else {
      response.success();
    }
  });
});
//create empty customer id
Parse.Cloud.define("newCutomer", function (request, response) {

   gateway.customer.create({}, function (err, result) {

   if (err) {
   console.log(err);
   response.error(err);
   } else {
     console.log(result.customer.id);
     response.success(result.customer.id);
   }
  });
});

//create new customer for cc save?
Parse.Cloud.define("createWithNonce", function (request, response) {
  var clientNew = request.params.clientId;
  var nonceFromTheClient = request.params.payment_method_nonce;
  console.log("here");
  console.log(nonceFromTheClient);
  gateway.customer.create({
  firstName: "Charity",
  lastName: "Smith",
  paymentMethodNonce: nonceFromTheClient
}, function (err, result) {
  result.success;
  // true

  result.customer.id;
  // e.g 160923
  console.log(result.customer.id);

  result.customer.paymentMethods[0].token;
  // e.g f28wm
    if (err) {
      console.log(err);
      response.error(err);
    } else {
      response.success(result.customer.id);
    } 
  });
});

在 iOS 中:

func makeCardPayment() {

        do {

            try PFCloud.callFunction("conektaCustomer", withParameters: ["name":nameUser, "email": "[email protected]", "phone":numeroDeTelefono, "tokenID":"tok_test_visa_4242", "total":monto])

        } catch let error {

            print(error.localizedDescription)

        }
    }

它只是抛出无效函数,仅此而已,有什么帮助吗?



Best Answer-推荐答案


所以,我在这里检查了函数:“conektaCustomer”中的第 21 行,您需要添加引号,如下行:



						

关于javascript - 云代码无效功能的back4app问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42322280/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap